Making Usage Statistics in PHP - Creating the Image Library (Page 5 of 7 ) Having the data, let's start to deal with the image creation library of PHP (GD). Its output is GIF/PNG/JPEG. It uses image resources. These are PHP variables representing images. Usually, in a program there is only one image resource. You can create an image resource using one of the following functions: - ImageCreate (int width, int height) - Creates a blank image resource
- ImageCreateTrueColor (int width, int height) - Creates a blank true color image resource
- ImageCreateFromGIF (string filename) - Creates an image resource using a given picture file
- ImageCreateFromJPEG (string filename) - Creates an image resource using a given picture file
- ImageCreateFromPNG (string filename) - Creates an image resource using a given picture file
This code can be good for this, but don't forget to call the header function because it's not HTML output! header ('Content-type: image/png'); $image=imagecreate(400,210);
Then you can start to draw the picture. Here are some of the functions - read them as we will use some to make the Top 10 stats. For more, see the PHP manual. - ImageColorAllocate (resource image, int red, int green, int blue) - Prepares an RGB color to use
- ImageLine (resource image, int x1, int y1, int x2, int y2, int color) - Draws a line
- ImageRectangle (resource image, int x1, int y1, int x2, int y2, int col) - Draws a rectangle
- ImagePolygon (resource image, array points, int num_points, int color) - Draws a polygon using an array
- ImageFilledRectangle (resource image, int x1, int y1, int x2, int y2, int color) - Draws a filled rectangle
- ImageTTFText (resource image, int size, int angle, int x, int y, int color, string fontfile, string text) - Draws a TrueType text
Below you can read the code. It can be a little confusing, especially the numeric expressions, because you have to think in X and Y coordinates. But try it, you'll get the hang of it! Next: Charting the Results >>
More PHP Articles More By Adam Szanto |