[ Team LiB ] Previous Section Next Section

Drawing an Arc

You can add partial or complete arcs to your images with the imagearc() function. imagearc() requires an image object, coordinates for the center point, an integer for width, an integer for height, a start point and end point (in degrees), and a color resource. Arcs are drawn clockwise starting from 3 o'clock. The following fragment draws a quarter circle:


imagearc( $image, 99, 99, 200, 200, 0, 90, $blue );

This draws a partial arc, with its center at the coordinates 99, 99. The total height and width are both 200 pixels. Drawing starts at 3 o'clock and continues for 90° (to 6 o'clock).

Listing 15.4 draws a complete circle and fills it with blue.

Listing 15.4 Drawing a Circle with imagearc()
1: <?php
2: header("Content-type: image/png");
3: $image = imagecreate( 200, 200 );
4: $red = imagecolorallocate($image, 255,0,0);
5: $blue = imagecolorallocate($image, 0,0,255 );
6: imagearc( $image, 99, 99, 180, 180, 0, 360, $blue );
7: imagefill( $image, 99, 99, $blue );
8: imagepng($image);
9: ?>

As before, we acquire color resources (lines 4 and 5). On line 6, we call imagearc() to draw a complete circle; then the call to imagefill() on line 7 fills our circle with blue.

Figure 15.4 shows the output from Listing 15.4.

Figure 15.4. Drawing a circle with imagearc().

graphics/15fig04.gif

    [ Team LiB ] Previous Section Next Section