将PNG放在PHP中的JPG上

Chr*_*ris 17 php gd image image-processing

我想在PHP中执行以下操作:

我有两个图像,一个jpg和一个png.我想将jpg的大小调整为与png相同的大小,然后将png置于顶部.PNG具有透明度,所以我想保留它,以便jpg显示在下面.

如果有人能提供帮助那就太棒了!

谢谢

sky*_*man 43

<?
$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);
?>
Run Code Online (Sandbox Code Playgroud)


web*_*kul 5

这是我使用的工作代码

$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);
Run Code Online (Sandbox Code Playgroud)