【发布时间】:2015-01-23 03:11:54
【问题描述】:
我需要这个:
我正在这样做:
$top_file = 'image1.png';
$bottom_file = 'image2.png';
$top = imagecreatefrompng($top_file);
$bottom = imagecreatefrompng($bottom_file);
// get current width/height
list($top_width, $top_height) = getimagesize($top_file);
list($bottom_width, $bottom_height) = getimagesize($bottom_file);
// compute new width/height
$new_width = ($top_width > $bottom_width) ? $top_width : $bottom_width;
$new_height = $top_height + $bottom_height;
// create new image and merge
$new = imagecreate($new_width, $new_height);
imagecopy($new, $top, 0, 0, 0, 0, $top_width, $top_height);
imagecopy($new, $bottom, 0, $top_height+1, 0, 0, $bottom_width, $bottom_height);
// save to file
imagepng($new, 'merged_image.png');
.. 但合并后的图像没有两个图像。 PHP 报告这个:
Warning: imagecreatefrompng(): '/Users/myusername/Work/www/projectname/staticimage.jpg' is not a valid PNG file in /Users/myusername/Work/www/projectname/imageWatermark.php on line 60
Warning: imagecopy() expects parameter 2 to be resource, boolean given in /Users/myusername/Work/www/projectname/imageWatermark.php on line 74
【问题讨论】:
-
它对我来说很好用。可以看到两张图片。
-
这里也一样。图像损坏?文件不存在?
-
顺便说一句,你可以使用
$new_width = max($top_width, $bottom_width)。 -
是的。我检查了不同的图像,然后发现图像损坏了。
-
是的,请提交答案,可能对其他人有帮助。
标签: php imagemagick gd image-manipulation