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

Using Brushes

In the same way that imagesettile() allows you to use a picture for filling, imagesetbrush() allows you to use a picture for an outline. While this could be a premade picture you've just loaded, you can get nice effects by using handmade pictures that are swept around basic shapes.

Figure 16-14 shows a picture of a lot of dots ranging in color from red to yellow—not very interesting, but great for using as a brush.

The picture we'll be using as our brush

Figure 16-14. The picture we'll be using as our brush

Those dots were created with this script:

    $brush = imagecreate(100,100);

    $brushtrans = imagecolorallocate($brush, 0, 0, 0);
    imagecolortransparent($brush, $brushtrans);

    for ($k = 1; $k < 18; ++$k) {
            $color = imagecolorallocate($brush, 255, $k * 15, 0);
            imagefilledellipse($brush, $k * 5, $k * 5, 5, 5, $color);
    }

    imagepng($brush);
    imagedestroy($brush);

The next step is to create a larger image, recreate that brush, and use it as the outline for a shape. Here's the code:

 $pic = imagecreatetruecolor(600,600); $brush = imagecreate(100,100); $brushtrans = imagecolorallocate($brush, 0, 0, 0); imagecolortransparent($brush, $brushtrans); for ($k = 1; $k < 18; ++$k) { $color = imagecolorallocate($brush, 255, $k * 15, 0); imagefilledellipse($brush, $k * 5, $k * 5, 5, 5, $color); } imagesetbrush($pic, $brush); imageellipse($pic, 300, 300, 350, 350, IMG_COLOR_BRUSHED); imagepng($pic); imagedestroy($pic); imagedestroy($brush); ...
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