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: ?> ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.