我希望用PHP实现以下功能:
我有两张图片,一张是jpg格式,另一张是png格式。我想将jpg格式的图片调整为与png格式相同的大小,然后将png放在其上方。由于PNG具有透明度,因此希望保留透明度,以便jpg显示在其下面。
如果有人能提供帮助,那就太好了!
谢谢!
我希望用PHP实现以下功能:
我有两张图片,一张是jpg格式,另一张是png格式。我想将jpg格式的图片调整为与png格式相同的大小,然后将png放在其上方。由于PNG具有透明度,因此希望保留透明度,以便jpg显示在其下面。
如果有人能提供帮助,那就太好了!
谢谢!
<?
$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 merge
imagecopymerge($dest, $src, 17, 13, 0, 0, 60, 100, 100);
// Output and free from memory
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);