PHP
  Home arrow PHP arrow Page 2 - Building an Image Generator Class with PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Building an Image Generator Class with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2007-10-01


    Table of Contents:
  • Building an Image Generator Class with PHP 5
  • Defining the basic structure of a image generator class in PHP 5
  • Implementing the buildImageStream() and displayImage() methods
  • Testing the ImageGenerator class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building an Image Generator Class with PHP 5 - Defining the basic structure of a image generator class in PHP 5
    ( Page 2 of 4 )

    As I explained in the beginning of this article, the initial structure of this image generator class will be rather simplistic. It will be composed of only two basic methods (except for the corresponding constructor), called "buildImageStream()" and "displayImage()" respectively.

    Obviously, as these names suggest, the first one will be tasked with building dynamically an image stream, while the second one will output it on the browser using a specific graphic format.

    Having said that, here's the basic signature of this image generator class. Have a look at it, please:

    // define 'ImageGenerator' class

      class ImageGenerator{

       private $width;

       private $height;

       private $bgColor;

       private $textColor;

       private $inputString;

       private $img;

    // initialize input arguments

    public function __construct($inputString='Default Input String',$width=400,$height=300,$bgColor='0,0,0',
    $textColor='255,255,255'){

      $this->inputString=$inputString;

       $this->width=$width;

       $this->height=$height;

       $this->bgColor=explode(',',$bgColor);

       $this->textColor=explode(',',$textColor);

       $this->buildImageStream();

    }

    // create image stream

      private function buildImageStream(){

    // implementation for this private method goes here

    // display image stream on the browser

      public function displayImage(){

    // implementation for this public method goes here

     }

    }

    As you can see, the definition of the above "ImageGenerator" class is very easy to follow, even though it's still incomplete. First, you may notice that the constructor takes up a few simple incoming parameters. These include the corresponding input string that will be embedded in the graphic output, and then the dimensions of the image stream being generated, and finally the foreground and background colors.

    Additionally, it's clear to see that the constructor also calls the private "buildImageStream()" method from inside its context. This will come in handy for generating the respective dynamic image stream on the fly, based upon the pertinent input arguments. However, for the sake of clarity, the implementation of this method and the "displayImage()" method will be covered in detail in the section to come.

    Thus, if you're interested in learning how these brand new methods that belong to the image generator class will be defined, please jump ahead and read the next few lines. I'll be there, waiting for you.



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek