单图片
//图片叠加
function imagealphaMerge($dst,$src,$d_x,$d_y,$s_x,$s_y,$s_w,$s_h,$alpha){ $dst_im = imagecreatefromjpeg($dst); $src_im = imagecreatefromjpeg($src); imagecopymerge($dst_im,$src_im,$d_x,$d_y,$s_x,$s_y,$s_w,$s_h,$alpha); imagejpeg($dst_im); imagedestroy($dst_im); imagedestroy($src_im); } imagealphaMerge('Chrysanthemum.jpg',$src,0,0,0,0,300,300,50);
多图片
$src = array('Koala.jpg','Tulips.jpg'); function imagealphaMerge($dst,$src,$d_x,$d_y,$s_x,$s_y,$s_w,$s_h,$alpha){ $dst_im = imagecreatefromjpeg($dst); $num = count($src); for ($i=0; $i<$num; $i++) { $src_im = imagecreatefromjpeg($src[$i]); imagecopymerge($dst_im,$src_im,$d_x,$d_y,$s_x,$s_y,$s_w,$s_h,$alpha); } imagejpeg($dst_im); imagedestroy($dst_im); imagedestroy($src_im); } imagealphaMerge('Chrysanthemum.jpg',$src,0,0,0,0,300,300,50);
这里是用jpg图片做的测试,如果其他图片请更换imagecreatefromjpeg,imagejpeg。同时修改图片路径