PHP - Add transparent PNG to GIF dynamically

好久不见. 提交于 2019-12-08 06:21:19

问题


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:

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

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:


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.



来源:https://stackoverflow.com/questions/13983557/php-add-transparent-png-to-gif-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!