CodeIgniter Forums

Full Version: image library - gd2 - png/gif resizing with transparency
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]woopsicle[/eluser]
hi all

i have some code to create a thumbnail of a given image. it all works fine - except when the uploaded image is a gif or png and has transparency.

in this case, it will produce an image with black where the transparency should have been.

1) can the image lib not just resize an image and keep transparency as is
2) if not, how can i make it so the transparency changes to white (i know this has something to do with using imagecreate rather than imagecreatetruecolor but i am not an expert to know how/where to change the Image Library code).

i am using gd2 by the way - i dont have imagemagick.. but if someone says it works in imagemagick then i will try to see if i can get it installed.

Thanks

El Forum

[eluser]woopsicle[/eluser]
no one can help with this?

El Forum

[eluser]ImageSmith[/eluser]
woopsicle i am guessing that you are working with a gif image. to maintain transparency in creating a new gif on the fly (which is pretty much what you do when resizing) you need to first allocate a background colour for the new image, then set that colour to be the transparent colour.

the order in which these functions are called is as follows:
Code:
imagecreatetruecolor // create new truecolor image
imagecolorallocate // allocate color to background
imagecolortransparent // nominate background color as transparent
imagecopyresampled  create a copy by resample
imagegif // generate gif from stuff you have just created

the arguments to these various functions you can find in the php manual.
to me it does not look like the Image_lib has been set up to work with gif transparency.
maybe i might have a shot at providing support for gif and png transparency in this library when i get a break in traffic. ;-)
unless, of course, some wonderful person has already contributed this work.