似乎很简单,不是:(
我正在尝试在图像(jpg)上添加类似水印(透明png)的内容。 这是我正在使用的代码:
$width = 800;
$height = 600;
$bottom_image = imagecreatefromjpeg("portrait1.jpg");
$top_image = imagecreatefrompng("man2.png");
imagesavealpha($top_image, true);
imagealphablending($top_image, true);
imagecopy($bottom_image, $top_image, 200, 200, 0, 0, $width, $height);
header('Content-type: image/png');
imagepng($bottom_image);
当我合并图像时,png位于正确的位置,上面和左边的每一个都很好(jpg被复制),但其他一切都是黑色的。
我尝试将imagesavealpha和imagealphablending设置为false,没有任何区别。
您可以在http://ekstrakt.selfip.com/photobomb/image.php
看到生成的图片我在网上搜索过,找不到解决办法。
感谢任何帮助。
答案 0 :(得分:3)
您的$width
和$height
应该是水印的尺寸,而不是照片的尺寸。你告诉它要做的是复制比它大得多的水印。当它读取不存在的图像的一部分(坐标超出界限)时,结果是不透明的黑色,给出你看到的结果。
答案 1 :(得分:1)
使用imagecopymerge()代替imagecopy()
你可能也喜欢imagesavealpha()