Close Search Box
Search Box

Search: From:

Close
Newsletter

9Tutorials to your Inbox



Image manipulations with PHP5 and GD

Image manipulations with PHP5 and GD
Author lv1 (3200/5000)
2,611 views
1 Star2 Star3Star4 Star5 Star (2 votes, average: 2.5 out of 5)

Before the release of PHP5 if one wanted to manipulate images by applying filters, you’d have to either use an ImageMagick extension or create complicated matrices which you would then use the imageconvolution function.
With the introduction of PHP5 a new function is available called imagefilter. The parameters for the imagefilter function are bool imagefilter ( resource $image, int $filtertype [, int $arg1 [, int $arg2 [, int $arg3]]] ). Like most image functions in php, the first parameter is an image resource object created using one of the imagecreatefrom functions.

The second parameter is the name of one of the available filters. These are:

  • IMG_FILTER_NEGATE -negates all the colors of the image.
  • IMG_FILTER_GRAYSCALE -converts the image to grayscale.
  • IMG_FILTER_BRIGHTNESS - changes the brightness of the image
  • IMG_FILTER_CONTRAST- changes the contrast of the image
  • IMG_FILTER_COLORIZE - colorscales the image to a given color
  • IMG_FILTER_EDGEDETECT- highlights the edges of the image
  • IMG_FILTER_EMBOSS -embosses an image
  • IMG_FILTER_GAUSSIAN_BLUR - blurs the image in a Gaussian fashion
  • IMG_FILTER_SELECTIVE_BLUR- blurs an image
  • IMG_FILTER_MEAN_REMOVAL - makes an image look “sketchy”

The third and subsequent parameters only apply to certain filters. For the brightness and contrast filters, the third parameter must be a number between -255 and 255 where 0 is no change to the image and 255 is the maximum brightness/contrast. The only other filter with requires more parameters is the colorize filter. The third, fourth, and fifth parameter must be the RGB value of the desired color respectively.

Here are a few examples of the filter in use:

original
Blur:
blur

Grayscale
blur

Brightness:
blur

As you can see complex effects are achieved more simply than in previous versions of php. If you wish to read more about the imgfilter function, check the PHP Manual

del.icio.us:Image manipulations with PHP5 and GD digg:Image manipulations with PHP5 and GD spurl:Image manipulations with PHP5 and GD newsvine:Image manipulations with PHP5 and GD blinklist:Image manipulations with PHP5 and GD furl:Image manipulations with PHP5 and GD reddit:Image manipulations with PHP5 and GD blogmarks:Image manipulations with PHP5 and GD Y!:Image manipulations with PHP5 and GD magnolia:Image manipulations with PHP5 and GD segnalo:Image manipulations with PHP5 and GD

Post a Comment »








Safari hates me

Comment Guidelines

  • Hyperlinks are automatically generated.
  • <em>italic</em>
  • <strong>bold</strong>