function mergerImg($imgs) {
list($max_width, $max_height) = getimagesize($imgs['dst']); //取得$imgs['dst']的图像大小
$dests = imagecreatetruecolor($max_width, $max_height); //新增一个真彩色图像
$dst_im = imagecreatefrompng($imgs['dst']); //由文件或 URL 创建一个新图
imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height); //拷贝图像的一部分
imagedestroy($dst_im); //销毁图片
$src_im = imagecreatefrompng($imgs['src']); //由文件或 URL 创建一个新图象。创建哆啦A梦图片
$src_info = getimagesize($imgs['src']); //取得$imgs['dst']的图像大小
imagecopy($dests,$src_im,$max_width/1.4,$max_height/1.6,0,0,$src_info[0],$src_info[1]); //将哆啦A梦丢入真彩色图像
imagedestroy($src_im); //清理图片缓存
$text_color = imagecolorallocate($dests, 255, 255, 255);//改变字体颜色
$font = dirname(__FILE__) . '/font/simhei.ttf'; //项目下的font文件必须有simhei.ttf字体文件
$text = mb_convert_encoding('多啦A梦','html-entities','utf-8'); //将网页转换编码为UTF-8
//$text = "哆啦A梦";//解决乱码问题
ImageTTFText($dests, 30, 0, 10, $max_height/1.1, $text_color, $font, $text);
header("Content-type: image/jpeg");
//imagestring($dests, 5, 0, 460, "哆啦A梦", $textcolor);
imagejpeg($dests);
}
//定义图片位置
$imgs = array(
'dst' => '图片路径1',
'src' => '图片路径2',
);
mergerImg($imgs);
list($max_width, $max_height) = getimagesize($imgs['dst']); //取得$imgs['dst']的图像大小
$dests = imagecreatetruecolor($max_width, $max_height); //新增一个真彩色图像
$dst_im = imagecreatefrompng($imgs['dst']); //由文件或 URL 创建一个新图
imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height); //拷贝图像的一部分
imagedestroy($dst_im); //销毁图片
$src_im = imagecreatefrompng($imgs['src']); //由文件或 URL 创建一个新图象。创建哆啦A梦图片
$src_info = getimagesize($imgs['src']); //取得$imgs['dst']的图像大小
imagecopy($dests,$src_im,$max_width/1.4,$max_height/1.6,0,0,$src_info[0],$src_info[1]); //将哆啦A梦丢入真彩色图像
imagedestroy($src_im); //清理图片缓存
$text_color = imagecolorallocate($dests, 255, 255, 255);//改变字体颜色
$font = dirname(__FILE__) . '/font/simhei.ttf'; //项目下的font文件必须有simhei.ttf字体文件
$text = mb_convert_encoding('多啦A梦','html-entities','utf-8'); //将网页转换编码为UTF-8
//$text = "哆啦A梦";//解决乱码问题
ImageTTFText($dests, 30, 0, 10, $max_height/1.1, $text_color, $font, $text);
header("Content-type: image/jpeg");
//imagestring($dests, 5, 0, 460, "哆啦A梦", $textcolor);
imagejpeg($dests);
}
//定义图片位置
$imgs = array(
'dst' => '图片路径1',
'src' => '图片路径2',
);
mergerImg($imgs);