Resizing images with correct gamma using PHP and GD | Linux Today

Resizing images with correct gamma using PHP and GD

Written By
Web Webster
Web Webster
Jul 23, 2010

“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.”


Complete Story

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.