0

我正在使用 imagecopymerge 创建图像,但覆盖在顶部的图像是 PNG,但透明部分是纯白色的。如何启用透明度?

$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);
4

2 回答 2

1

所以我终于找到了解决方案。它正在使用imagecopy().

这是将我推向正确方向的文章。

这花了好几个小时的研究!

于 2013-01-11T03:07:31.567 回答
0

采用imagecolortransparent()

在这里阅读更多

编辑:更好的解决方案在这里:

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

于 2013-01-10T20:50:27.497 回答