Page 1 of 1

How did you fix PNG transparency in resized images please?

Posted: Wed Jul 19, 2006 12:41 am
by steveparks
Hi

I'm struggling with a problem in some code that i'm writing. I need to upload an resize images using GDlib, but whenever I do this with transparent PNGs it gives them a black background.

Searching Google for possible solutions I came across this page: http://www.s9y.org/32.html (the todo list)

which has this excerpt:
"! Figure out how to preserve PNG and GIF transparency when resizing images with GDlib (FIX: PNG transparency works)"

Please could one of the developers shed some light on how you fixed this for PNGs please?

I'd really appreciate you help (and will donate!)

cheers
steve

Posted: Thu Jul 20, 2006 7:29 am
by judebert

Code: Select all

    /* Attempt to copy transparency information, this really only works for PNG */
    if (function_exists('imagesavealpha')) {
        imagealphablending($out, false);
        imagesavealpha($out, true);
    }
There may be other stuff in there, too. Check include/functions_images.inc.php.

Thanks

Posted: Sat Jul 22, 2006 11:38 pm
by steveparks
Hi

Many thanks for the suggestion. I've tried this out (the same code is at php.net) and am getting quality issues, with some black 'interference' around edges of the image.

Here's an example:
Image

notice around the ears? it doesn't seem to deal well with curved edges.

Did you find a way to get round this in Serendipity please?

Thanks alot

Steve

Re: Thanks

Posted: Mon Jul 24, 2006 12:03 pm
by garvinhicking
Hi!

What you can see there is the effect of lacking support for differentiaded transparency. Rounded edges are "simulated" by different levels of transparency (between 0 and 255). GIF for example only supports full (1) or no (0) transparency.

It might be related to your PHP setup, if this is possible. Which GDLib version are you using?

Serendipity can't do anything about this, this is completely up to the image processing tool (gdlib or imagemagick).

Best regards,
Garvin