Need help with GD using PNGs.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gbrad
Forum Newbie
Posts: 1
Joined: Sun Jul 13, 2003 9:31 pm

Need help with GD using PNGs.

Post 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.
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post 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,
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post 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.
Post Reply