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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.