SunQuest
 
       PHP
  Home arrow PHP arrow Page 2 - Building an Image Generator Class with...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
PHP

Building an Image Generator Class with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · As you’ll probably know, PHP 5 really shines when it comes to building...
     

       

    PHP ARTICLES

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway