Blame docs/naturaldocs/preamble.txt

Packit ed3af9
Title: About LibGD @VERSION@
Packit ed3af9
Packit ed3af9
What is gd?:
Packit ed3af9
Packit ed3af9
gd is a graphics library. It allows your code to quickly draw images
Packit ed3af9
complete with lines, arcs, text, multiple colors, cut and paste from
Packit ed3af9
other images, and flood fills, and write out the result as a PNG or
Packit ed3af9
JPEG file. This is particularly useful in World Wide Web applications,
Packit ed3af9
where PNG and JPEG are two of the formats accepted for inline images
Packit ed3af9
by most browsers.
Packit ed3af9
Packit ed3af9
gd is not a paint program. If you are looking for a paint program, you
Packit ed3af9
are looking in the wrong place. If you are not a programmer, you are
Packit ed3af9
looking in the wrong place, unless you are installing a required
Packit ed3af9
library in order to run an application.
Packit ed3af9
Packit ed3af9
gd does not provide for every possible desirable graphics
Packit ed3af9
operation. It is not necessary or desirable for gd to become a
Packit ed3af9
kitchen-sink graphics package, but version 2.0 does include most
Packit ed3af9
frequently requested features, including both truecolor and palette
Packit ed3af9
images, resampling (smooth resizing of truecolor images) and so forth.
Packit ed3af9
Packit ed3af9
gd basics: using gd in your program:
Packit ed3af9
Packit ed3af9
gd lets you create PNG or JPEG images on the fly. To use gd in your
Packit ed3af9
program, include the file gd.h, and link with the gd library and the
Packit ed3af9
other required libraries; the syntax for most Unix flavors is:
Packit ed3af9
Packit ed3af9
> -lgd -lpng -lz -ljpeg -lfreetype -lm
Packit ed3af9
Packit ed3af9
Assuming that all of these libraries are available.
Packit ed3af9
Packit ed3af9
If you want to use the provided simple fonts, include gdfontt.h,
Packit ed3af9
gdfonts.h, gdfontmb.h, gdfontl.h and/or gdfontg.h. For more impressive
Packit ed3af9
results, install FreeType 2.x and use the gdImageStringFT function. If
Packit ed3af9
you are not using the provided Makefile and/or a library-based
Packit ed3af9
approach, be sure to include the source modules as well in your
Packit ed3af9
project.
Packit ed3af9
Packit ed3af9
Here is a short example program. (For a more advanced example, see
Packit ed3af9
gddemo.c, included in the distribution. gddemo.c is NOT the same
Packit ed3af9
program; it demonstrates additional features!)
Packit ed3af9
Packit ed3af9
>/* Bring in gd library functions */
Packit ed3af9
>#include "gd.h"
Packit ed3af9
>
Packit ed3af9
>/* Bring in standard I/O so we can output the PNG to a file */
Packit ed3af9
>#include <stdio.h>
Packit ed3af9
>
Packit ed3af9
>int main() {
Packit ed3af9
>  /* Declare the image */
Packit ed3af9
>  gdImagePtr im;
Packit ed3af9
>  /* Declare output files */
Packit ed3af9
>  FILE *pngout, *jpegout;
Packit ed3af9
>  /* Declare color indexes */
Packit ed3af9
>  int black;
Packit ed3af9
>  int white;
Packit ed3af9
>
Packit ed3af9
>  /* Allocate the image: 64 pixels across by 64 pixels tall */
Packit ed3af9
>  im = gdImageCreate(64, 64);
Packit ed3af9
>
Packit ed3af9
>  /* Allocate the color black (red, green and blue all minimum).
Packit ed3af9
>    Since this is the first color in a new image, it will
Packit ed3af9
>    be the background color. */
Packit ed3af9
>  black = gdImageColorAllocate(im, 0, 0, 0);  
Packit ed3af9
>
Packit ed3af9
>  /* Allocate the color white (red, green and blue all maximum). */
Packit ed3af9
>  white = gdImageColorAllocate(im, 255, 255, 255);  
Packit ed3af9
>  
Packit ed3af9
>  /* Draw a line from the upper left to the lower right,
Packit ed3af9
>    using white color index. */
Packit ed3af9
>  gdImageLine(im, 0, 0, 63, 63, white);  
Packit ed3af9
>
Packit ed3af9
>  /* Open a file for writing. "wb" means "write binary", important
Packit ed3af9
>    under MSDOS, harmless under Unix. */
Packit ed3af9
>  pngout = fopen("test.png", "wb");
Packit ed3af9
>
Packit ed3af9
>  /* Do the same for a JPEG-format file. */
Packit ed3af9
>  jpegout = fopen("test.jpg", "wb");
Packit ed3af9
>
Packit ed3af9
>  /* Output the image to the disk file in PNG format. */
Packit ed3af9
>  gdImagePng(im, pngout);
Packit ed3af9
>
Packit ed3af9
>  /* Output the same image in JPEG format, using the default
Packit ed3af9
>    JPEG quality setting. */
Packit ed3af9
>  gdImageJpeg(im, jpegout, -1);
Packit ed3af9
>
Packit ed3af9
>  /* Close the files. */
Packit ed3af9
>  fclose(pngout);
Packit ed3af9
>  fclose(jpegout);
Packit ed3af9
>
Packit ed3af9
>  /* Destroy the image in memory. */
Packit ed3af9
>  gdImageDestroy(im);
Packit ed3af9
>}
Packit ed3af9
>