PHP
  Home arrow PHP arrow Page 3 - Drawing Functions and the GD Library i...
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      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


    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


       · Over the course of this second installment of the series, you'll learn the basis on...
       · From the article, in regards to imagecharup(): "the character has been rotated 90...
       · Thank you commenting on my PHP article and for pointing me that correction on using...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





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