PHP
  Home arrow PHP arrow Page 3 - Drawing Functions and the GD Library 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? 
PHP

Drawing Functions and the GD Library in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2007-08-21


    Table of Contents:
  • Drawing Functions and the GD Library in PHP
  • Taking a look at the imagearc() function
  • Using the imagechar() and imagecharup() functions
  • Using the imageellipse() and imagefilledellipse() functions

  • 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


    Drawing Functions and the GD Library in PHP - Using the imagechar() and imagecharup() functions
    ( Page 3 of 4 )

    As I stated in the previous section, the GD library also provides PHP developers with a couple of intuitive functions for displaying single characters on a specified image stream. In this case, I'm talking about the "imagechar()" and "imagecharup()" functions respectively, whose basic usage is clearly demonstrated by the following code samples:

    // example of 'imagechar()' function

    try{
       if(!$img=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // allocate some colors
       $whiteColor=imagecolorallocate($img,255,255,255);
       $blackColor=imagecolorallocate($img,0,0,0);
       // display character
       imagechar($img,5,150,90,'X',$whiteColor);
       header('Content-type: image/png');
       imagepng($img);
       // free memory
       imagedestroy($img);

    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    // example of 'imagecharup()' function

    try{
       if(!$img=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // allocate some colors
       $whiteColor=imagecolorallocate($img,255,255,255);
       $blackColor=imagecolorallocate($img,0,0,0);
       // display character
       imagecharup($img,5,150,90,'A',$whiteColor);
       header('Content-type: image/gif');
       imagegif($img);
       // free memory
       imagedestroy($img);

    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    As illustrated previously by the above pair of hands-on examples, displaying different characters on a specified image stream is actually a no-brainer process that can be performed with minor hassles. In the first case, a simple "X" character is included into a basic image stream via the corresponding "imagechar()" function. Quite simple, right?

    In the second example, the "imagecharup()" function is properly utilized to display another basic character in front of a black-colored image stream. In this case, the character has been rotated 90 degrees clockwise, since this function allows you to specify the inclination angle used to show the character in question.

    So far, so good. At this point I showed you how to display a few basic characters in front of a previously-created image stream, by using the pair of simple GD functions that you learned previously. As you may have noticed, the aforementioned functions aren't actually as useful as the powerful "imagestring()" that you saw in the first tutorial of this series, but they did deserve a close look, since they could be helpful in certain circumstances.

    Now, going back to covering the functions provided by the GD library to draw basic shapes on specific image streams, in the following section I'll teach you how to display on the browser some primitive ellipses, something that can be quite helpful if your PHP application requires you to work with this type of shape.

    To learn how to display some elemental ellipses with the GD library, please click on the link below and keep reading.



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

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT