PHP
  Home arrow PHP arrow Page 2 - Creating Image Streams from Existing G...
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 
Moblin 
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

Creating Image Streams from Existing Graphics with the GD Library in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2007-08-20

    Table of Contents:
  • Creating Image Streams from Existing Graphics with the GD Library in PHP
  • Building image streams from existing GIF graphics
  • Building an image stream from an existing JPG graphic
  • Building image streams from an existing PNG graphic

  • 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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    Creating Image Streams from Existing Graphics with the GD Library in PHP - Building image streams from existing GIF graphics


    (Page 2 of 4 )

    As I explained at the beginning of this article, the GD library provides PHP developers with a decent set of functions for generating different image streams from existing graphics. This can be helpful when a particular web application needs to preprocess a determined number of background pictures, although there may be other cases where these functions can be pretty effective too.

    Concerning the implementation of these image preprocessing functions, in the preceding article of the series I showed you how to create a brand new image stream from an existing GIF picture using the "imagecreatefromgif()" function. Let me refresh your memory with the following two code samples:

    // example of 'imagecreatefromgif()' function

    try{
       if(!$image=imagecreatefromgif('clouds.gif')){
          throw new Exception('Error loading image');
       }
       // create text color for gif image
       if(!$textColor=imagecolorallocate($image,0,0,0)){
          throw new Exception('Error creating text color');
       }
       // include text string into gif image
       if(!$text=imagestring($image,5,10,90,'This is a sample text
    string.',$textColor)){
          throw new Exception('Error creating image text');
       }
       header("Content-type:image/gif");
       // display image
       imagegif($image);
       // free up memory
       imagedestroy($image);
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    // example of custom function using 'imagecreatefromgif()'

    try{
       // define 'displayGifImage()' function
       function displayGifImage($image,$text){
          if(!file_exists($image)){
             throw new Exception('Invalid image file');
          }
          if(!$text){
             throw new Exception('Invalid text for image');
          }
          if(!$image=imagecreatefromgif($image)){
             throw new Exception('Error loading image');
          }
          // create text color for gif image
          if(!$textColor=imagecolorallocate($image,0,0,0)){
             throw new Exception('Error creating text color');
          }
          // include text string into gif image
          if(!imagestring($image,5,10,90,$text,$textColor)){
             throw new Exception('Error creating image text');
          }
          header("Content-type:image/gif");
          // display image
          imagegif($image);
          // free up memory
          imagedestroy($image); 
       }
       displayGifImage('clouds.gif','This is a sample string.');
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    As you can see, the practical examples shown above demonstrate in a clear way how to create a dynamic image stream from an existing GIF graphic. Of course, once the original picture is built via the corresponding "imagecreatefromgif()" function, it can be later modified and displayed in any other format supported by the browser, such as JPG and PNG respectively.

    And speaking of these popular image formats, in the following section I'll teach you how to use another handy function included into the neat GD extension to build several image streams from an existing JPG graphic.

    Want to see how this function looks? Click on the link that appears below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · Over the course of this second part of the series, you'll learn how to use the GD...
     

       

    PHP ARTICLES

    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - 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...




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