Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Color and Image Fills

The function imagefill() takes four parameters: an image resource, the X and Y coordinates to start the fill at, and the color with which to fill. The fill will automatically flood your image with color outward from the point specified by your X and Y parameters until it encounters any other color.

Put this imagefill() function call into your addingtext.php script, just after imagettftext():

    $red = imagecolorallocate($image, 255, 0, 0);
    imagefill($image, 0, 0, $red);

With that function, our red color is used to fill in the image starting from (0,0), which is the top-left corner. If you load the script into your web browser, you will see the fill has left some parts of the blue behind—the parts it couldn't "reach" inside the text. Also, you will notice there is a bluish fringe around the text, where the white text was anti-aliased (smoothed) against the blue background, producing a blue-white edge to the text. Figure 16-12 shows how the fill looks with the blue areas that could not be reached inside letters. Figure 16-13 shows a close-up of the letter "o," where you can see the anti-aliasing in action. As our fill starts on blue, it will not fill over any other shade of blue, which is why this fringe has been left there.

Our first fill leaves blue areas inside letters, and also a blue fringe around each of the letters

Figure 16-12. Our first fill leaves blue areas inside letters, and also a blue fringe around each of the letters

Figure 16-13. Anti-aliasing has ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page