发生这种情况的最佳方法可能是在内存中创建具有所需组合尺寸的新图像,然后将现有图像复制或重新采样到新图像,然后将新图像保存到磁盘。
例如:
function merge($filename_x, $filename_y, $filename_result) {
// Get dimensions for specified images
list($width_x, $height_x) = getimagesize($filename_x);
list($width_y, $height_y) = getimagesize($filename_y);
// Create new image with desired dimensions
$image = imagecreatetruecolor($width_x + $width_y, $height_x);
// Load images and then copy to destination image
$image_x = imagecreatefromjpeg($filename_x);
$image_y = imagecreatefromgif($filename_y);
imagecopy($image, $image_x, 0, 0, 0, 0, $width_x, $height_x);
imagecopy($image, $image_y, $width_x, 0, 0, 0, $width_y, $height_y);
// Save the resulting image to disk (as JPEG)
imagejpeg($image, $filename_result);
// Clean up
imagedestroy($image);
imagedestroy($image_x);
imagedestroy($image_y);
}
例:
merge('images/myimg.jpg', 'images/second.gif', 'images/merged.jpg');
0
我有两个图像要合并,然后保存到新位置。
我希望将第二张图像放置在第一张图像的正下方。
我有以下内容,但该图像甚至无法保存。
两张图片的宽度均为316px X 100px
根据上面的代码,$ destimg现在应该为316x200,但这不会发生。也喜欢将其作为新图像并保存到另一个文件夹。
谢谢你的帮助。