【问题标题】:Transparent PNG over JPG in PHPPHP中的透明PNG而不是JPG
【发布时间】:2011-12-20 14:21:21
【问题描述】:

看起来很简单,其实不是:(

我正在尝试在图像 (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看到生成的图像

我已经在网上搜索了,我找不到解决方案。

感谢任何帮助。

【问题讨论】:

  • 您还必须在 $bottom_image 上启用字母混合。

标签: php image png transparency php-gd


【解决方案1】:

您的$width$height 应该是水印的尺寸,而不是照片的尺寸。你告诉它做的是复制比它大得多的水印。当它读取不存在的图像的一部分(坐标超出范围)时,结果是不透明的黑色,给出您看到的结果。

【讨论】:

    【解决方案2】:

    使用imagecopymerge() 代替imagecopy()

    你也可能喜欢imagesavealpha()

    【讨论】:

      猜你喜欢
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多