Creating and Outputting Images

Before you can begin to work with an image, you must acquire an image resource. You can do this using the imagecreate() function. imagecreate() requires two arguments, one for the image’s height and another for its width. It returns an image resource, which you will use with most of the functions we cover in this hour. You should be familiar with resources from your work with files and databases. The image resource returned by imagecreate() is a required argument for most of the functions in this book:

$image = imagecreate( 200, 200 );

Now that you have an image resource, you can allocate a color.

If you want to ...

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.