對於這種情況,最佳方法可能是在內存中創建一個新圖像,然後將所需圖像複製或重新採樣到新圖像,然後將新圖像保存到磁盤。
例如:
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');
你見過你的PHP的版本,而這需要的版本? – clement 2012-01-13 23:18:45
感謝您的回覆。我在描述中添加了php 5,但它從我認爲的mods中刪除。 – 2012-01-13 23:20:13