看似简单,其实不然:(
我正在尝试在图像 (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 查看生成的图像
我在网上搜索过,找不到解决方案。
感谢任何帮助。
最佳答案
您的 $width
和 $height
应该是水印的尺寸,而不是照片的尺寸。您告诉它要做的是复制比实际尺寸大得多的水印。当它读取不存在的图像部分(坐标越界)时,结果是不透明的黑色,给出您看到的结果。
关于php - 在 PHP 中通过 JPG 透明 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7985583/