======================================图片上加文字==========================================
一、这种是直接显示在浏览器上,并不保存
function aaa(){
$user_id = 168955;
$bigImgPath = 'http://h-cdn.zealcdn.cn/20180706140903.png'; //原图,可以是本地力或者在线图片
$img = imagecreatefromstring(file_get_contents($bigImgPath));
$font = './Public/ziti/dkzt.ttc'; //一定要有对应的字体文件
$black = imagecolorallocate($img, 0,255,0); //字体颜色 RGB
$fontSize = 10; //字体大小
$circleSize = 0; //旋转角度
$left = 10; //左边距
$top = 20; //顶边距
=“要加的内容”; //要加的
imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $str);
list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
switch ($bgType) {
case 1: //gif
header('Content-Type:image/gif');
ob_clean();
imagegif($img);
break;
case 2: //jpg
header('Content-Type:image/jpg');
ob_clean();
imagejpeg($img);
break;
case 3: //jpg
header('Content-Type:image/png');
ob_clean();
imagepng($img);
break;
default:
break;
}
$insert['vip_id']=168955;
$insert['download_time']=$time;
$challenge_img = M("challenge_img")->add($insert);
imagedestroy($img);
}
二、这各在后边中路径和文件名的同保存到指定 的文件夹下
function img_id($img_url,$user_id){
$img = imagecreatefromstring(file_get_contents($img_url));
$font = 'public/dkzt.ttc';//字体文件
$black = imagecolorallocate($img,255, 255, 255);//字体颜色 RGB
$fontSize = 20; //字体大小
$circleSize = 0; //旋转角度
$left = 50; //左边距
$top = 210; //顶边距
imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, '要加的文字内容');
list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
switch ($bgType) {
case 1: //gif
header('Content-Type:image/gif');
ob_clean();
imagegif($img,'public/img/666.gif');
break;
case 2: //jpg
header('Content-Type:image/jpg');
ob_clean();
imagejpeg($img,'public/img/666.jpg');
break;
case 3: //jpg
ob_clean();
header('Content-Type:image/png');
imagepng($img,'public/img/666.png');
break;
default:
break;
}
imagedestroy($img);
}
====================================图片上加图片(加二维码)============================
$path_1 = 'http://h-cdn.zealcdn.cn/20180711150108.png'; //广告图
$path_2 = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data='.$url; //二维码图片
$image_1 = imagecreatefrompng($path_1);
$image_2 = imagecreatefrompng($path_2);
// 创建真彩画布
$image_3 = imageCreatetruecolor(imagesx($image_1),imagesy($image_1));
// 为真彩画布创建白色背景
$color = imagecolorallocate($image_3, 255, 255, 255);
imagefill($image_3, 0, 0, $color);
// 设置透明
// imageColorTransparent($image_3, $color);
// 复制图片一到真彩画布中(重新取样-获取透明图片)
imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
// 与图片二合成
imagecopymerge($image_3, $image_2, 40, 370, 0, 0, imagesx($image_2), imagesy($image_2), 100);
// 输出合成图片
imagepng($image_3,'public/share_img/'.$vip_id.'.png');