Advanced

Resizing images with correct gamma using PHP and GD

Posted by Sander_Marechal on · 4 comments
Lone Wolves; By Sander Marechal (The Netherlands)
Mail this story
Print this story

A short while ago "Ty W" posted an interesting question on StackOverflow. Apparently, most graphics software cannot scale images the right way. Usually it's hard to notice the flaw but the linked article does a great job of explaining the problem. PHP's GD library suffers from the same issue, but Ty discovered that the sample PHP program provided with the article did not work on partially transparent images. After a couple of hours of fiddling I managed to get a working solution. Apparently, the imagegammacorrect() function in PHP deals badly with images that have an alpha channel. I suspect that it tries to apply the same calculation to the alpha channel that it applies to the red, green and blue channels. To work around this, my solution splits the aplha channel from the original image. The alpha channel is resampled regularly while the red, green and blue channels are resampled using gamma correction.

Full Story

  Nav
» Read more about: Story Type: Editorial, Tutorial; Groups: PHP

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (4)

Sorry, that's not me. That's "Sander de Kievit", a totally different Dutch guy. I noticed that on the last article of him that you posted. You had my name as the author. I corrected it for you :-D
Well F@RT! I looked all over for a last name, and saw it was Sander from the Netherlands, and assumed it was you.

Phooey.

Oh well, they're still good articles. Sigh.
Sander is actually a pretty common name in The Netherlands. I guess about as popular as Alex or something in the US. I couldn't find his last name on his site either, but it's in the URL.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post