PHP – Add transparent PNG to GIF dynamically

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?

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories