php -> 合成两张图片为一张

直接输出图片

<?PHP   
//两张图片合成方法
$A = "./5/1.png";

   
 
$imgs= $A;   
$target = 'emp.jpg';//背景图片 
$target_img = Imagecreatefromjpeg($target); 

$sourece_img = Imagecreatefrompng($imgs);  
$sourece_size = getimagesize($imgs);


$tmp=2; 
$tmpy=2; //图片之间的间距 
header('Content-Type: image/jpeg');
imagecopy($target_img,$sourece_img,$tmp,$tmpy,0,0,$sourece_size[0],$sourece_size[1]); 

Imagejpeg($target_img,null);
//清楚缓存
imagedestroy($target_img); 
imagedestroy($sourece_img)
?>  

保持图片 到 服务器

<?PHP   
//两张图片合成方法
$A = "./5/1.png";

   
 
$imgs= $A;   
$target = 'emp.jpg';//背景图片 
$target_img = Imagecreatefromjpeg($target); 

$sourece_img = Imagecreatefrompng($imgs);  
$sourece_size = getimagesize($imgs);


$tmp=2; 
$tmpy=2; //图片之间的间距  
imagecopy($target_img,$sourece_img,$tmp,$tmpy,0,0,$sourece_size[0],$sourece_size[1]); 

Imagejpeg($target_img,'pin.jpg');
//清楚缓存
imagedestroy($target_img); 
imagedestroy($sourece_img)
?>  
<img src="pin.jpg">

猜你喜欢

转载自mft.iteye.com/blog/2310731