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

More Shapes

Using three new functions, we can make a much more complicated image. These are: imagecreatetruecolor(), imagefilledellipse(), and imagefilledarc().

Here is a script using these new functions:

    header("content-type: image/png");

    $image = imagecreatetruecolor(400,300);
    $blue = imagecolorallocate($image, 0, 0, 255);
    $green = imagecolorallocate($image, 0, 255, 0);
    $red = imagecolorallocate($image, 255, 0, 0);

    imagefilledellipse($image, 200, 150, 200, 200, $red);
    imagefilledellipse($image, 200, 150, 180, 180, $blue);
    imagefilledellipse($image, 200, 150, 50, 50, $red);
    imagefilledarc($image, 200, 150, 200, 200, 345, 15, $green, IMG_ARC_PIE);
    imagefilledarc($image, 200, 150, 200, 200, 255, 285, $green, IMG_ARC_PIE);
    imagefilledarc($image, 200, 150, 200, 200, 165, 195, $green, IMG_ARC_PIE);
    imagefilledarc($image, 200, 150, 200, 200, 75, 105, $green, IMG_ARC_PIE);

    imagepng($image);
    imagedestroy($image);

The output from that script is shown in Figure 16-3.

Ellipses and circles

Figure 16-3. Ellipses and circles

Using imagecreatetruecolor() is the same as imagecreate()—it takes the same two parameters, and returns an image resource that is freed using imagedestroy(). The difference between the two is that imagecreatetruecolor() returns an image with a true-color palette, whereas an image made by imagecreate() cannot contain more than 256 colors. Furthermore, the image resource returned by imagecreatetruecolor() ...

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