php合并png与jpg图片
以下php代码完美解决png图片与jpg图片的合并,并且解决php处理png透明显示黑色的问题
<?php $png = imagecreatefrompng('./mark.png');$jpeg = imagecreatefromjpeg('./image.jpg');list($width, $height) = getimagesize('./image.jpg');list($newwidth, $newheight) = getimagesize('./mark.png');$out = imagecreatetruecolor($newwidth, $newheight);imagecopyresampled($out, $jpeg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);imagecopyresampled($out, $png, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);imagejpeg($out, 'out.jpg', 100);?>
另外一种方法:
$dest = imagecreatefrompng('mapCanvas.png');$src = imagecreatefromjpeg('si.jpg');imagealphablending($dest, false);imagesavealpha($dest, true);// Copy and mergeimagecopymerge($dest, $src, 17, 13, 0, 0, 60, 100, 100);// Output and free from memoryheader('Content-Type: image/png');imagepng($dest);imagedestroy($dest);imagedestroy($src);
转载请注明:FKBlog » php合并png与jpg图片(http://www.fkblog.org/blog820)