合并大图像上的小图像

时间:2015-05-11 07:31:46

标签: php gd

我有一个尺寸为190W和40H的小图像。我需要将此图像合并/放置在尺寸为650W和148H的大图像上。我尝试了很多东西,但没有一个能奏效。目前我正在使用代码

大图

enter image description here

小图片

enter image description here

$png = imagecreatefrompng('images/bigimage.png');

$jpeg = imagecreatefromjpeg('images/smallimage.jpg');

list($width, $height) = getimagesize('images/smallimage.jpg');

list($newwidth, $newheight) = getimagesize('images/bigimage.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, 'images/saved.png');

这产生了我需要的结果。但问题是小图像在像

这样的大图像上是像素化的

我得到的输出是这样的,小图像是像素化的。请有人帮助我做到这一点。

enter image description here

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。希望这对某人有所帮助。

$png = imagecreatefrompng('images/bigimage.png');

$jpeg = imagecreatefromjpeg('images/smallimage.jpg');

list($width, $height) = getimagesize('images/smallimage.jpg');

list($newwidth, $newheight) = getimagesize('images/bigimage.png');

$out = imagecreatetruecolor($newwidth, $newheight);

$jpeg_canvas = imagecreatetruecolor($width, $height);

imagecopyresampled($jpeg_canvas, $jpeg, 0, 0, 0, 0, $width, $height, $width, $height);
//imagejpeg($out, 'images/saved.jpg'); exit;
imagecopyresampled($out, $png, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);
imagecopyresampled($out, $jpeg_canvas, 135, 15, 0, 0, $width, $height, $width, $height);
imagejpeg($out, 'images/saved.jpg');