PHP
  Home arrow PHP arrow Page 2 - An Image is Worth a Thousand Words in PHP
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

An Image is Worth a Thousand Words in PHP
By: Brian Vaughn
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2005-12-14


    Table of Contents:
  • An Image is Worth a Thousand Words in PHP
  • Project Overview
  • Setting Up Our Class
  • The Browser Problem

  • 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


    An Image is Worth a Thousand Words in PHP - Project Overview
    ( Page 2 of 4 )

    Admittedly, the program we are about to develop may lack an immediate, real-world application. So rather than contrive a situation in which we, as developers, would be asked to create such an application, let’s simply talk about what we will be designing our program to do. The benefits of such an exercise will then become clear as we work through the various stages of development.

    The basic goal of our application is simple: receive as a parameter a string designating the location of an image file (this can be a local image or a remote one), load the image, and convert it to a string of colored text that resembles the original picture. To go a step beyond that, we will also allow for multiple output modes including: color, grayscale, monochrome, and matrix. This will allow users to convert images to a variety of text-only formats. Below you’ll see a couple of ‘teaser’ sample images, displaying conversions in each of our various output formats:

     

    We’re going to be using an object-oriented programming approach, so we will start off by creating a class to contain our image manipulation methods. Let’s call this class ‘img_to_txt’, and let’s store it in a file named ‘img_to_txt.php’. For now its contents should be as follows:

    <?php
    # used to convert images to text-only format
    class img_to_txt {

    } # END img_to_txt class
    ?>

    Although there may not be an immediate need to re-use the methods we are about to create, it is still a good programming practice to make them as portable as possible. (After all, you never know when you may want to re-use something!) Because of this, we've chosen to bundle all of our code inside a simple helper class – but this class needs a few get-and-set methods in order to function properly. That’s what we’ll spend the first part of this article focusing on. Each of these methods will be pretty self-explanatory, and will simply allow us to define certain attributes of our image (such as its location, and the desired output format).



     
     
    >>> More PHP Articles          >>> More By Brian Vaughn
     

       

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek