PHP
  Home arrow PHP arrow Page 2 - Drawing Functions and the GD Library i...
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 
Moblin 
JMSL Numerical Library 
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 - Taking a look at the imagearc() function


    (Page 2 of 4 )

    In consonance with the concepts that I explained at the introduction of this article, the GD library comes well-equipped with a neat number of drawing functions. These functions are useful when utilized within a specific PHP application that requires the display of different types of basic shapes to users.

    The GD extension can also help you create complex images, like 2D and 3D graphics, flow charts, and pie drawings, by using the appropriate set of functions provided by the library in question.

    Please take a look at the following code sample, which demonstrates how to use the "imagearc()" function to display obviously different arcs. Here are the corresponding examples, so take some time and study them:

    // example of 'imagearc()' function - draws a white arc

    try{
       if(!$img=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // allocate a basic color
       if(!$whiteColor=imagecolorallocate($img,255,255,255)){
         throw new Exception('Error allocating color');
       }
       // draw a white arc
       imagearc($img,100,100,100,100,0,360, $whiteColor);
       // display image to the browser
       header("Content-type: image/png");
       imagepng($img);
       // free memory
       imagedestroy($img);
               
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    As you can see, the above "imagearc()" GD function is tasked with displaying several types of arcs on a given image stream. It takes up a few intuitive input parameters, such the image stream resource to draw on, the respective start and end coordinates, and finally the arc inclination and its corresponding color.

    The previous script will display on the browser a white-colored arc, similar to the one shown below:

    Due to the great versatility exposed by this function, it's possible to create several types of arcs, with different colors. The following examples illustrate this concept very clearly, so have a look at them, please:

    // example of 'imagearc()' function - draws a red arc

    try{
       if(!$img=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // allocate a basic color
       if(!$redColor=imagecolorallocate($img,255,0,0)){
         throw new Exception('Error allocating color');
       }
       // draw a red arc
       imagearc($img,100,100,100,100,0,360,$redColor);
       // display image to the browser
       header("Content-type: image/png");
       imagepng($img);
       // free memory
       imagedestroy($img);
              
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    // example of 'imagearc()' function - draws a green arc

    try{
       if(!$img=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // allocate some basic colors
       if(!$greenColor=imagecolorallocate($img,255,255,255)){
         throw new Exception('Error allocating color');
       }
       // draw a green arc
       imagearc($img,100,100,100,100,0,360,$greenColor);
       // display image to the browser
       header("Content-type: image/png");
       imagepng($img);
       // free memory
       imagedestroy($img);
              
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    Okay, at this point I believe that you now understand how to use the GB extension to draw a few basics arcs on a given image stream, thus it's time to move forward and continue exploring more functions that come integrated with this library.

    And speaking of analyzing some additional functions bundled with the GD library, in the section to come I'll show you how to use two more functions to display some basic characters on a specified image stream.

    To see how this will be achieved, jump ahead and read the next few lines. I'll be there, waiting for you.

    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

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





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