Acquiring Color

To work with color, you need to acquire a color resource. You can do this with the imagecolorallocate() function, which requires an image resource and three integers between 0 and 255 representing red, green, and blue. The function returns an image resource that you can use to define the color of shapes, fills, and text:

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

Coincidentally, the first time you call imagecolorallocate(), you also set the default color for your image.

Now that you have an image resource and a color allocated, you are nearly ready to output your first image to the browser. To do this, you need to use the imagepng() function, which requires the image resource as an argument. imagepng() also accepts an optional ...

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.