TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Advertisement
The Big GD Guide - Part 3
   Part 3

Welcome to part 3 of the big GD guide. In this part we shall be dealing with more shapes and also dealing with things like fonts and other cool functions.

Shapes

Circles

We can create circles using the GD library this can be a great effect for creating pie charts for instance.

PHP Code:
imageellipse     resource $image    int $cx    int $cy    int $width    int $height    int $color    
PHP Code:
image     //An image resource, returned by one of the image creation functions,  such as imagecreatetruecolor().
cx    //x-coordinate of the center       
cy   //y-coordinate of the center       
width   //The ellipse width       
height  //The ellipse height       
color  //The color of the ellipse. A color identifier created with        imagecolorallocate() 
How does it work?

We can see how all the cords for the circle work by using the following diagram.

http://img232.imageshack.us/img232/2725/circle1ye8.png

You can see that the X & Y cords apply to the center point of the circle. If you place the cords at 10 by 10 then the circle will be cut off the screen because the center will be in the top left hand corner.

The Arc

You can also deal with arcs in GD this is also good for piecharts in fact the arc and the circle will both work in comparisons to create the chart.

PHP Code:
imagearc     resource $image    int $cx    int $cy    int $width    int $height    int $start    int $end    int $color    
PHP Code:

image  
//An image resource, returned by one of the image creation functions,  such as imagecreatetruecolor().
cx  //x-coordinate of the center       
cy  //y-coordinate of the center       
width  //The arc width       
height //The arc height       
start  //The arc start angle, in degrees.       
end   //The arc end angle, in degrees.  0° is located at the three-o'clock position, and the arc is drawn clockwise.
color   //A color identifier created with         imagecolorallocate() 
http://img230.imageshack.us/img230/9921/circle2dz8.png

Now as with all shapes in GD you can make things "filled" or not.This means you can either make the actual shape filled with a colour or just give it a line colour.

I shall be explaining them both they are pretty much the same thing just give a different effect.

Style for arc


PHP Code:
imagefilledarc     resource $image    int $cx    int $cy    int $width    int $height    int $start    int $end    int $color    int $style    
PHP Code:
image  //An image resource, returned by one of the image creation functions,  such as imagecreatetruecolor().
cx   // x-coordinate of the center       
cy  //y-coordinate of the center       
width   //The arc width       
height  //The arc height       
start    //The arc start angle, in degrees.       
end     //The arc end angle, in degrees.        0° is located at the three-o'clock position, and the arc is drawn        clockwise.       
color   //A color identifier created with         imagecolorallocate()       
style 
Arc Styles
  1. IMG_ARC_PIE
  2. IMG_ARC_CHORD
  3. IMG_ARC_NOFILL
  4. IMG_ARC_EDGED

You can see what each of them do here

Font

You can load font into your GD image using a function.

PHP Code:
imageloadfont     string $file    
You can load the font via a directly on your web server. Then use the fontin the imagestring function we talked about in part 2

PHP Code:
$font imageloadfont("04b.gdf");
imagestring($im$font00"Hello"$black); 
[/size]
Report this Article
Last 5 Article Reviews Read All Reviews
There are no reviews for this Article

All times are GMT. The time now is 11:42 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design