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

March 13, 2009 at 10:00 am
(4) adem says:

What about the quality?

April 25, 2009 at 3:51 pm
(5) alekciy says:

Great THX for article! I’t help me create greyscale image in PHP4.

Leave a Comment

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

Discuss
Community Forum
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

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

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

All rights reserved.