Web Development

8 Cool Functions in the GD2 extension

Most PHP developers have at least heard of GD2; thanks to its prolific use in CAPTCHA generation, the image functions in PHP are standard practice for many. But the extension’s uses don’t end there. After the fold, here are eight cool things you probably weren’t aware could be done with GD2, and might be useful for your web applications.

(Note that a few of these may not be available depending on your PHP/GD setup, check the manual)

  1. Get the size of an icon file, with getimagesize() (also works on all standard image formats)
  2. Apply a gaussian-blur to an image, with imagefilter()
  3. Rotate an image, with imagerotate()
  4. Flood-fill an area of an image, with imagefill()
  5. Grayscale an image, also with imagefilter()
  6. Draw polygons and arcs — maybe for mathematical diagram? — with imagepolygon() and imagearc()
  7. Copy and resize a section of an image, with imagecopyresized()
  8. “Sketchify” images for a pencil-illustration-style effect, also with imagefilter() (see a pattern here?)

The phpied blog has some cool demos of the imagefilter() function download one night stand in particular.

About the author

Written by .

If you found this post useful you may also want to check these out:

  1. Using PHP 5s XSL Extension to Perform XSL Transformations
  2. Making a Cool Anime Header in Photoshop
  3. Event Handlers and Callback Functions in JavaScript
  4. Design a Cool Old Book with Photoshop
  5. Using PHP 4s DOM XML Functions to Create XML Files from SQL Data
  6. Parallel web scraping in PHP: cURL multi functions