Home arrow PHP arrow Building an Image Generator Class with PHP 5

Building an Image Generator Class with PHP 5

In this article, you will learn how to build an image generator class with PHP 5, using the functions bundled with the GD library. Such a class has a wide variety of uses, but for the purposes of this three-part series, we will focus on creating a function for displaying noisy images (also known as captchas) on the browser.

  1. Building an Image Generator Class with PHP 5
  2. Defining the basic structure of a image generator class in PHP 5
  3. Implementing the buildImageStream() and displayImage() methods
  4. Testing the ImageGenerator class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 13
October 01, 2007

print this article




Undeniably, PHP is widely recognized by many web programmers as a general server-side scripting language with a remarkable capacity for tackling the development of a huge variety of applications. These applications can range from basic form validation classes and efficient database abstraction layers to more complex projects, such as fully-featured discussion forums, powerful web-based MySQL front-ends and popular content management systems.

The release of PHP 5 has provided seasoned PHP developers with a robust set of functions and object-based features that make this version of the scripting language one of the most used for building robust web applications with minor hassles. This versatility is particularly in evidence when it comes to generating and manipulating dynamic image streams via the popular GD extension. This library comes packaged with a neat arsenal of graphic processing functions for quickly and easily developing image-centric applications.

However, it isn't my intention to provide you a with a detailed guide on how to put the GD extension to work for you, since I already wrote an extensive series of articles, which were published here, on the prestigious Developer Shed Network.

Instead, I'd like to take a different course of action, slightly more pragmatic, and show you how to utilize some of the functions bundled with the GD library to build a highly expansible image generator class. Thanks to its fairly skeletal structure, this class will be easy to customize to suit the requirements of different PHP applications.

In simple terms, over the course of this brand new PHP series, which will be comprised of three friendly tutorials, I'll walk you through the development of an easy-to-follow PHP class that will have the ability to build dynamic text strings, which will be outputted straight to the browser in the form of image streams.

Of course, if you reread the previous sentence, then you'll realize the huge range of PHP applications that might take advantage of the basic functionality provided by the class that I plan to create here. In this case, however, I'll focus the whole development process on using the class in question to build an application aimed at displaying noisy images (also widely known as captchas).

The structure of this image generating class will be extremely pluggable, which implies that you can use it for other purposes, but hopefully the whole learning experience will serve as an introduction to using some functions included with the GD extension in the context of the object-oriented paradigm.

All right, providing that the development of an image generator class with PHP 5 may be an interesting topic to you, let's not waste more time in preliminaries and start building the core structure of this PHP 5-based class. It's going to be an instructive journey, trust me!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: