News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Philip Norton's Blog:
Desaturate Images With PHP
September 07, 2011 @ 12:51:26

In a new post to his blog Philip Norton shows how to desturate images with PHP using the already built-in GD libraries and the imagecopymergegray function.

To desaturate an image means to remove all non-greyscale colours from it, essentially creating a black and white version. To do this you can use the function imagecopymergegray(), which is part of the GD image library. This function is a little difficult to figure out, but what is does is sample one image into another and optionally changing the amount of colours that are kept during the sampling process. The function can be made to sample just a section of the image, or the whole thing.

He also offers an alternative method that uses imagefilter instead, passing it the IMG_FILTER_GRAYSCALE flag. Included is a full block of code for a method he recently included in a WordPress site to dynamically create thumbnails.

0 comments voice your opinion now!
desaturate image grayscale gd tutorial imagecopymergegray imagefilter


blog comments powered by Disqus

Similar Posts

PHPMaster.com: Under the Hood of Yii's Component Architecture, Part 3

NETTUTS.com: The Newbie's Guide to Test-Driven Development

Stuart Herbert's Blog: Can You Secure A Shared Server With PHP + FastCGI?

Pierre\'s Blog: What\'s new in GD, 5.1.x

Aleksey Martynov's Blog: Getting started with lexa-tools: Blog in 15 Minutes


Community Events

Don't see your event here?
Let us know!


community release introduction interview voicesoftheelephpant unittest laravel5 wordpress psr7 development library api opinion laravel conference extension framework series language podcast

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework