Forum Moderators: coopster

Message Too Old, No Replies

Convert JPEG to PNG using PHP?

         

pboreham

11:45 am on Aug 2, 2005 (gmt 0)

10+ Year Member



Hi all,

I am currently making a website that has e-comm functions and a back end for the client.

I want them to be able to upload images - but they need to be transparent. I do not want to leave this in the hands of the client, so I am looking at ways of using the GD library to make the change (wow, arent the images functions of PHP vast!?).

Is there a way to do the following:-

1) Upload Image (I can do this) - will be a JPG on white background.

2) Convert JPEG to PNG and then set the background of the PNG (#FFFFFF) to the transparent colour.

3) Save as PNG and output as a transparent image.

I have already got a script working that displays transparent PNG's in all IE versions - that works fine, so will not be an issue.

I can already upload an image, create an image in the GD library and show it to the screen with a new filename - its just the bit in the middle I am stuck on! I am not even sure it is possible...?

Thanks for any help,

Paul

jatar_k

3:20 pm on Aug 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so it is just setting the bg colour to white that is tripping you up?

haven't done much image rewriting myself, have you tried anything code, did you get anywhere?

pboreham

3:46 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



I tried a few bits of PHP - seems there is no way of converting a JPG to a PNG (though you can with a gif using GIF2PNG command).

I have gone basic for now and trying to work just with PNG's - ignoring the conversion for now.

I managed to open an existing PNG into the GD library, then I used the PHP commands from the PHP manual to (supposedly) set the transparent colour to #FFFFFF and set the Alpha channel to on and saved this. Then showed the image on the page.

It had done *something* as there was some slight damage to the image (a few pixels of the image were transparent), but the background was still white.

The site is going to look horrid with images on white backgrounds!... bad planning!