首页 > 代码库 > php透明合并png与jpg图片

php透明合并png与jpg图片

 1 <?php 2 $png = imagecreatefrompng(‘./mark.png‘); 3 $jpeg = imagecreatefromjpeg(‘./image.jpg‘); 4  5 list($width, $height) = getimagesize(‘./image.jpg‘); 6 list($newwidth, $newheight) = getimagesize(‘./mark.png‘); 7 $out = imagecreatetruecolor($newwidth, $newheight); 8 imagecopyresampled($out, $jpeg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 9 imagecopyresampled($out, $png, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);10 imagejpeg($out, ‘out.jpg‘, 100);11 ?>
 1 另外一种方法: 2  3 $dest = imagecreatefrompng(‘mapCanvas.png‘); 4 $src = imagecreatefromjpeg(‘si.jpg‘); 5 imagealphablending($dest, false); 6 imagesavealpha($dest, true); 7 // Copy and merge 8 imagecopymerge($dest, $src, 17, 13, 0, 0, 60, 100, 100); 9 10 // Output and free from memory11 header(‘Content-Type: image/png‘);12 imagepng($dest);13 14 imagedestroy($dest);15 imagedestroy($src);