Page 269 - Open Soource Technologies 304.indd
P. 269
Unit 11: Graphics
in mathematics and physics, the angle zero is the positive horizontal axis (East; also called the Notes
polar axis) and angles are measured counterclockwise (either in degrees or radians.) However,
in the bearing system used in navigation, the positive vertical axis (North) is taken as the zero
angles, and bearings are measured clockwise. The figure 11.4 shows the measures. For the
Macintosh/Windows raster, it makes sense to use the positive horizontal axis for zero and
measure counterclockwise, as only one quadrant is on the screen.
In addition, because some people prefer to graph in degrees and others in radians, a graphing
module perhaps ought to provide the option to do either.
Figure 11.4: Angle Measurement and Coordinate System
11.4 Creating and Drawing Images
For now, let’s start with the simplest possible GD example. Given Example is a script that
generates a black filled square. The code works with any version of GD that supports the PNG
image format.
A black square on a white background (black.php)
<?php
$im = ImageCreate(200,200);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,150,150,$black);
header(‘Content-Type: image/png’);
ImagePNG($im);
?>
Example illustrates the basic steps in generating any image: creating the image, allocating
colours, drawing the image, and then saving or sending the image. Figure 11.5 shows the output
of Example is.
Figure 11.5: A Black Square on a White Background
LOVELY PROFESSIONAL UNIVERSITY 263