Draw text using PHP GD,TTF fonts
For built-in GD fonts, use ImageString() php function.
Example:
<?php ImageString($image, 1, $x, $y, 'THIS TEXT WILL BE SHOWN', $text_color); ?>
TrueType fonts can be used to render text as images, using ImageTTFText() php function.
Example:
<?php ImageTTFText($image, $size, 0, $x, $y, $text_color, '/path/to/font.ttf', 'THIS TEXT WILL BE SHOWN'); ?>
Draw filled black circle with PHP
The ImageFillToBorder() function floods a region beginning at ($x,$y) with the color specified as the last parameter until it hits the edge of the canvas or runs into a line with the same color as the third parameter.
$image = ImageCreate(100,100); $bg = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); ImageArc($image, 50, 50, 100, 100, 0, 360, $black); ImageFillToBorder($image, 50, 50, $black, $black);
Draw open black circle centered in PHP
The following example draws an open black circle with a diameter of 100 pixels centered on the canvas.
$image = ImageCreate(100,100); $bg = ImageColorAllocate($image, 255, 255, 255); $black = ImageColorAllocate($image, 0, 0, 0); ImageArc($image, 50, 50, 100, 100, 0, 360, $black);
Drawing Arcs, Ellipses, and Circles with PHP
The first parameter is the canvas. The next two parameters are the x and y coordinates for the center position of the arc. After that comes the arc width and height. Since a circle is an arc with the same width and height, to draw a circle, set both numbers to the diameter of the circle. The sixth and seventh parameters are the starting and ending angles, in degrees.
Draw an arc, use ImageArc( ):
ImageArc($image, $x, $y, $width, $height, $start, $end, $color);
Draw an ellipse, use ImageArc( ) and set $start to 0 and $end to 360:
ImageArc($image, $x, $y, $width, $height, 0, 360, $color);
Draw a circle, use ImageArc( ), set $start to 0, set $end to 360, and use the same value for both $width and $height:
ImageArc($image, $x, $y, $diameter, $diameter, 0, 360, $color);
Drawing Lines, Rectangles, and Polygons with PHP
The first parameter is the canvas to draw on. The next set of parameters are the x and y coordinates to specify where GD should draw the shape. In ImageLine( ), the four coordinates are the endpoints of the line, and in ImageRectangle( ), they’re the opposite corners of the rectangle. For example, ImageLine($image, 0, 0, 100, 100, $color) produces a diagonal line. Passing the same parameters to ImageRectangle( ) produces a rectangle with corners at (0,0), (100,0), (0,100), and (100,100).
Draw a line by using ImageLine():
ImageLine($image, $x1, $y1, $x2, $y2, $color);
Draw an open rectangle by using ImageRectangle( ):
ImageRectangle($image, $x1, $y1, $x2, $y2, $color);
Draw a solid rectangle by using ImageFilledRectangle( ):
ImageFilledRectangle($image, $x1, $y1, $x2, $y2, $color);
Draw an open polygon by using ImagePolygon( ):
$points = array($x1, $y1, $x2, $y2, $x3, $y3); ImagePolygon($image, $points, count($points)/2, $color);
Draw a filled polygon by using ImageFilledPolygon( ):
$points = array($x1, $y1, $x2, $y2, $x3, $y3); ImageFilledPolygon($image, $points, count($points)/2, $color);
