douqi5079 2012-12-21 02:38
浏览 75

PHP - 动态地将透明PNG添加到GIF

I am trying to do a watermark mark with the php code, and everything seems to work fine, until I put a transparent PNG file to a GIF. This what happens:

enter image description here

So instead of transparent black watermark, I get this semi solid green thing on the top. The watermark is enter image description here

I use the following php code:

    ...
    $image = imagecreatefromgif($filepath);;
    $watermark_image = imagecreatefrompng($wm_filepath);
    imagealphablending($watermark_image, false);
    imagesavealpha($watermark_image, true);
    imagegif($image, $filepath);
    imagedestroy($image);


    imagecopy($image, $watermark_image, $offset['x'], $offset['y'], 0, 0, imagesx($watermark_image), imagesy($watermark_image) );

p.s. I have to mention that I tried to combine different settings using

    imagealphablending()
    imagesavealpha() 

and got no result

UPD:

Now I am saving image as a png file. I deleted these two rows imagealphablending($watermark_image, false); imagesavealpha($watermark_image, true); and it worked. However, the transparency of PNG is overlapping GIF. imagealphablending($image, true); didn't help. What shall I do?

  • 写回答

1条回答 默认 最新

  • dpaal28266 2012-12-21 02:40
    关注

    GIF files are limited to 256 colours and have a single colour designated as transparent. So you can't have antialiased transparency, nor can you have much antialiasing of any kind.

    I suggest saving as PNG instead.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP