1. Home
  2. Computing & Technology
  3. PHP / MySQL
photo of Angela Bradley

Angela's PHP / MySQL Blog

By Angela Bradley, About.com Guide to PHP / MySQL

Grayscale Images in PHP

Wednesday June 21, 2006

Alexa before and after we grayscale

Using the GD Library, we can convert a color image to a black and white (grayscale) image from a PHP file. We first read the file, and then convert each pixel of it to a corresponding gray value before creating our final grayscale image.

Comments

July 11, 2007 at 12:24 am
(1) Andrei Iscu says:

Hello,

About your Grayscale images with php article… There is a faster and easier way… the imagefilter function.
imagefilter($img, IMG_FILTER_GRAYSCALE);
Also, when dealing with PNG’s and GIF’s with transparency, the imagesavealpha function should be called with the save flag set to true so that the transparency channer is fully saved.
Here’s my little png snippet (I use it when building online menus that need grayscale buttons when they are not available; it uses 2 GET parameters: img -> it points to the filename (either absolute or relative paths) and g -> if it is defined, give the grayscale image.

Cheers!

August 25, 2007 at 6:18 am
(2) Dennis Hoppe says:

Hi, there is a easier way. The function is calling ImageCopyMergeGray and it’s very faster! ;)

April 26, 2008 at 4:33 pm
(3) Nerath says:

Dennis: That function isn’t even close to being accurate

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL

©2008 About.com, a part of The New York Times Company.

All rights reserved.