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()
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()
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
- IMG_ARC_PIE
- IMG_ARC_CHORD
- IMG_ARC_NOFILL
- 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 )
PHP Code:
$font = imageloadfont("04b.gdf");
imagestring($im, $font, 0, 0, "Hello", $black);


Join the friendly bunch on IRC...