An Intro to Using the GD Image Library with PHP - Getting to Know the Functions
(Page 2 of 6 )
OK, let's take a look at some of the functions we will be using in order to create the clock.
int ImageCreate(int x_size, int y_size) |
This one is simple enough; all we need to do is pass this function two integers that represent the width and height of the image we are creating. This function returns an identifier to our blank image. Worth noting is that the upper left corner of an image is the coordinate 0,0. That means if you create an image with a width of 100, the x coordinates will run from 0 through 99.
int ImageDestroy (int im) |
With ImageDestroy, we can get rid of the images we create with ImageCreate.
int ImageColorAllocate(int im, int red, int green, int blue) |
The first parameter to this function is the image identifier that we will have assigned by the ImageCreate function. Remember good old RGB colors? I hope so, you need to use them here. The next three parameters are the values for red, green and blue respectively. Some common colors are (0,0,0) for black, (255,255,255) for white and (255,0,0) for red. Here's a link to a good RGB chart that I found. If for some reason the function fails to allocate the color, it will return a value of -1.
int ImageFilledRectangle (int im, int x1, int y1, int x2, int y2, int col) |
This function is used to create a simple filled rectangle or square. All you do is pass it the image you are working with, upper left x-y coordinates, the lower right x-y coordinates and a color that you created with ImageColorAllocate. Remember that images start at 0,0!
Next: More Functions >>
More Miscellaneous Articles
More By Matt Wade