[ Team LiB ] Previous Section Next Section

Applying Color Fills

You can fill an area with color using PHP just as you can with your favorite graphics application. The function imagefill() requires an image resource, starting coordinates for the fill it is to perform, and a color resource. It then transforms the starting pixel and all adjacent pixels of the same color. Listing 15.3 adds a call to imagefill() to our script, making the image a little more interesting.

Listing 15.3 Using imagefill()
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: imageline( $image, 0, 0, 199, 199, $blue );
7: imagefill( $image, 0, 199, $blue );
8: imagepng($image);
9: ?>

The only change we have made to our example is the call to imagefill() on line 7. Figure 15.3 shows the output from Listing 15.3.

Figure 15.3. Using imagefill().

graphics/15fig03.gif

    [ Team LiB ] Previous Section Next Section