Drawing a New Image

The basic PHP function used to create a new image is called ImageCreate(), but creating an image is not as simple as just calling the function. Creating an image is a stepwise process and includes the use of several different PHP functions.

Creating an image begins with the ImageCreate() function, but all this function does is set aside a canvas area for your new image. The following line creates a drawing area that is 150 pixels wide by 150 pixels high:

$myImage = ImageCreate(150,150);

With a canvas now defined, you should next define a few colors for use in that new image. The following examples define five such colors, using the ImageColorAllocate() function and RGB values:

 $black = ImageColorAllocate($myImage, 0, 0, ...

Get Sams Teach Yourself PHP, MySQL® and Apache All in One 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.