Forum Moderators: coopster

Message Too Old, No Replies

Image Transparency with PHP File Uploads

         

username

6:29 pm on May 21, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi, I have a file upload facility which allows a user to upload a gif, jpg or png to the server. However when I upload a file that has a transparent background (i.e a gif or png) it sets the background to black. I have tried using a few php features to set the background to white, such as imagecolorallocate etc, but have had no success. Does anyone have a good method for doing this?

Thanks in advance.

username

12:36 am on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



So has anyone got any ideas on this one? I know it is a little out of the ordinary.

russkern

1:02 am on May 23, 2008 (gmt 0)

10+ Year Member



Don't know if I can help or not, but I do that sort of thing a lot with a simple & straight file upload script that you can find practicly anywhere on the web...

I upload transparent .gif files with it and they are just fine...

Are you resizing the images or creating a new one before upload? or just uploading an unaltered file?

username

1:55 am on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi russkren, I am doing the resizing before the upload is finalised on the temporary file. Don't know if this is causing issues?

russkern

2:06 am on May 23, 2008 (gmt 0)

10+ Year Member



Check out this thread... it seems to be talking about the same thing you are experiencing...

[forums.devshed.com...]

Google is a great thing.

username

2:53 am on May 23, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanks for the tips... got it sorted. All I had to do was proces the image for saving with transparency:

$trnprt_indx = imagecolorallocate($this->image, 256, 256, 256);
imagecolortransparent($this->image, $trnprt_indx);
imagegif($this->image,$filename);

Cool script because you can define the transparent color to match your page. Mine was white, so white it was.

Thanks heaps.

russkern

11:45 am on May 23, 2008 (gmt 0)

10+ Year Member



Glad to be able to help...