Page 1 of 1

Need help with GD using PNGs.

Posted: Sun Jul 13, 2003 9:31 pm
by gbrad
Hey, I'm pretty new to PHP. I'd like to overlay one PNG on top of another to create a new, composited image. They will always be the same size, I've already taken care of that. Part of one of the images is transparent, and I want the other image to show through that - creating a frame of sorts. How do I do this? Is there a way to afterward convert the new image to a JPEG so that I can be sure it will be supported in all browsers? Or do all the newer browsers have good enough PNG support to do this kind of on/off transparency? Thanks in advance.

Posted: Tue Jul 15, 2003 8:51 am
by cactus
I think the thread below may help. It is applicable to JPEGs but should give you the understanding/start you need to rectify your issue.

Ref : viewtopic.php?t=10618

Regards,

Posted: Tue Jul 15, 2003 9:29 am
by pootergeist
or [blatant plug mode on] you could try this manipulations class I wrote and use the merge() function therein

http://www.teckis.com/scriptix/thumbnails/teck.html

all you'd need is a call to the class to instantiate the object and then a call to merge

$variable = new Thumbnail('resource.jpg',200,150,'output_image.jpg',85,'');
$variable->merge('overlay.png',5,-35,65,'FF0000');
$variable->create();

which would take overlay.png and place it 5px from the left and 35px from the base at an opacity of 65% and dictating a fully transparent colour as pure red (note: the red on the png does not need to be transparent - the merge logic just ignores that colour totally).
if you use some code to grab your image size and define the 200,150 as found_width, found_height then there would be no size reduction.

[/plug mode off]

also note: most manual entries at php.net seem to indicate that GD has an awkward habit of only recognizing transparency if the index colour is black.