LibGD is an open source code library for the creation of images dynamically by programmers. GD is written in C, and “wrappers” are available for Perl, PHP and other languages. GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve website development.
GD is written in C Programming Language and various binding are available for different languages like C#, clip. D, Javascript, Lua, Pearl, PHP, Pascal, Python and ruby. The library was originally developped by Thomas Boutell and is now maintained by Pierre-A. Joye under the umbrella of PHP.net.
Home Page: Dynamic Creation of Images
Download: LibGD Releases
Here is a short example program. (For a more advanced example, see gddemo.c, included in the distribution. gddemo.c is NOT the same program; it demonstrates additional features!)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/* Bring in gd library functions */ #include "gd.h" /* Bring in standard I/O so we can output the PNG to a file */ #include <stdio.h> int main() { /* Declare the image */ gdImagePtr im; /* Declare output files */ FILE *pngout, *jpegout; /* Declare color indexes */ int black; int white; /* Allocate the image: 64 pixels across by 64 pixels tall */ im = gdImageCreate(64, 64); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ pngout = fopen("test.png", "wb"); /* Do the same for a JPEG-format file. */ jpegout = fopen("test.jpg", "wb"); /* Output the image to the disk file in PNG format. */ gdImagePng(im, pngout); /* Output the same image in JPEG format, using the default JPEG quality setting. */ gdImageJpeg(im, jpegout, -1); /* Close the files. */ fclose(pngout); fclose(jpegout); /* Destroy the image in memory. */ gdImageDestroy(im); } |