PHP
  Home arrow PHP arrow Page 2 - 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? 
Google.com  
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 - 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
     

       

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