PHP
  Home arrow PHP arrow Page 4 - Drawing More Complex Shapes with the 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

Drawing More Complex Shapes with the GD Library in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-08-22

    Table of Contents:
  • Drawing More Complex Shapes with the GD Library in PHP
  • Displaying filled images and arcs
  • Drawing filled polygons with the GD library
  • Retrieving information about a given image stream

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Drawing More Complex Shapes with the GD Library in PHP - Retrieving information about a given image stream


    (Page 4 of 4 )

    In consonance with the concepts that I discussed in the section you just read, this last section will be focused upon covering the functions integrated with the GD package that retrieve the physical dimensions of a given image stream.

    To perform these tasks, the library offers the handy "imagex()" and "imagey()" functions, which can be used to retrieve the width and height of a specified image respectively.

    A pair of simple implementations for these functions is shown below, so study the corresponding code samples:

    // example of 'imagesx()' function

    try{
       if(!$image=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // display image width
       echo 'The image is '.imagesx($image).'pixels width';
       // displays: The image is 300pixels width
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    // example of 'imagesy()' function try{
       if(!$image=imagecreatetruecolor(300,200)){
         throw new Exception('Error creating image');
       }
       // display image height
       echo 'The image is '.imagesy($image).'pixels height';
       // displays: The image is 200pixels height
    }
    catch(Exception $e){
       echo $e->getMessage();
       exit();
    }

    Admittedly, getting the width and height values of a given image stream is actually a straightforward procedure, considering the simplicity of the functions. As you saw, they only take a reference of the image stream used to calculate its respective dimensions. Quite easy, right?

    Finally, as I said earlier, the GD library also offers another powerful function that fetches relevant information on a concrete image stream. This function is called "getimagesize()." It not only retrieves the respective width and height of the stream, but returns its MIME type as well in an array notation.

    Below I coded a demonstrative example that shows how to use this function: 

    // example of 'getimagesize()' function

       if(!$imageData=getimagesize('clouds.gif')){
         throw new Exception('Error getting image data');
       }
       // display image data
       echo 'Image data is as following<br />';
       echo 'Image width: '.$imageData[0].'px <br />';// Image
    width :300px 
       echo 'Image height: '.$imageData[1].'px <br />';// Image
    height :200px
       echo 'MIME type: '.$imageData['mime'].'<br />';// MIME type:
    image/gif

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

    See how easy it is to retrieve relevant information about a given image stream using the previous "getimagesize()" function? I'm sure you do! Of course, it's worthwhile to mention here that all of the examples included in this tutorial are just that: a friendly introduction to using the most important functions bundled with the GD extension. For full information about this package, the best place to go is the PHP official site.

    Final thoughts

    In this fourth part of the series, I walked you through using the GD functions that draw basic filled shapes, ranging from simple rectangles to more complex polygons. I also showed you a few additional functions for retrieving the dimensions of a specified image stream.

    In the last part of the series, I'll teach you how to take advantage of the capacity offered by the GD package to apply different types of filters to an existing graphic.

    Now that you've been warned, I think you won't want to miss it!  


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In this part of the series, you'll learn the key concepts on how to use the set of...
     

       

    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 5 hosted by Hostway