How did you fix PNG transparency in resized images please?

Discussion corner for Developers of Serendipity.
Post Reply
steveparks
Posts: 2
Joined: Wed Jul 19, 2006 12:36 am

How did you fix PNG transparency in resized images please?

Post 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
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post 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.
Judebert
---
Website | Wishlist | PayPal
steveparks
Posts: 2
Joined: Wed Jul 19, 2006 12:36 am

Thanks

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Thanks

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply