frozenpeas
Technical User
Hi,
I am having trouble laying a PNG with transparency over a jpg using imagecopymerge. I believe I am having one of the following problems:
1. the PNG file is not being loaded with its alpha channel
2. I have an error in the way I'm using imagecopymerge
The result I am getting is a jpg of the PNG with a black background instead of the underlying jpg that I want showing through.
If I comment out the imagecopymerge line, the thumbnail image is built properly. But of course, I am missing the image overlay I need.
I hope it is something that is painfully obvious to someone but just unfamiliar to me. I haven't done much with PHP and images.
Thanks in advance.
frozenpeas
I am having trouble laying a PNG with transparency over a jpg using imagecopymerge. I believe I am having one of the following problems:
1. the PNG file is not being loaded with its alpha channel
2. I have an error in the way I'm using imagecopymerge
The result I am getting is a jpg of the PNG with a black background instead of the underlying jpg that I want showing through.
If I comment out the imagecopymerge line, the thumbnail image is built properly. But of course, I am missing the image overlay I need.
I hope it is something that is painfully obvious to someone but just unfamiliar to me. I haven't done much with PHP and images.
Thanks in advance.
Code:
$thumb_src = $tmp;
$thumb = imagecreatetruecolor(197,158);
imagecopyresampled($thumb,$thumb_src,0,0,0,0,197,158,$newwidth,$newheight);
//do the image overlay
//load Image and get its size
$overlay_size = getimagesize("../gallery/_images/template.png");
$overlay_tmp = imagecreatefrompng("../gallery/_images/template.png");
//convert the image to PNG-24
$overlay = imagecreatetruecolor($overlay_size[0],$overlay_size[1]);
imagecopy($overlay,$overlay_tmp,0,0,0,0,$overlay_size[0],$overlay_size[1]);
imagedestroy($overlay_tmp);
//create the image file
imagecopymerge($thumb,$overlay,0,0,0,0,197,158,100);
imagejpeg($thumb,"../gallery/_images/th_".$filename,70);
imagedestroy($thumb);
frozenpeas