0

I'm creating an image with imagecopymerge, but the image being overlaid on top, is a PNG but the transparent part is pure white. How do I enable transparency?

$image = imagecreatefromjpeg($this->getFile());

    $size = getimagesize($this->getFile());  

    $watermark = imagecreatefrompng('../watermark.png');
    $watermark_width = imagesx($watermark);  
    $watermark_height = imagesy($watermark);

    $dest_x = $size[0] - $watermark_width - 10;  

    $dest_y = $size[1] - $watermark_height - 5; 

    //die($watermark_width);

    $thumb_image = imagecreatetruecolor($this->getThumbWidth(), $this->getThumbHeight());

    imagealphablending($thumb_image,true);
    imagealphablending($image,true);

    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  

    imagecopyresampled( $thumb_image, $image, 0, 0, 0, 0, $this->getThumbResizeWidth(), $this->getThumbResizeHeight(), $this->getWidth(), $this->getHeight() );
    imagejpeg( $thumb_image, $this->getThumbDestination(), $this->getThumbQuality() );

    imagedestroy($thumb_image);
    imagedestroy($image);
Adam
  • 9,189
  • 15
  • 46
  • 62

2 Answers2

1

So I FINALLY found a solution. It's using imagecopy().

Here is the article that nudged me in the right direction.

That took quite a few hours of research!

kittycat
  • 14,983
  • 9
  • 55
  • 80
Adam
  • 9,189
  • 15
  • 46
  • 62
0

Use imagecolortransparent()

Read more here

EDIT: A better solution is here:

https://stackoverflow.com/a/313103/1533203

Community
  • 1
  • 1
David Harris
  • 2,697
  • 15
  • 27