The following demonstration program is supposed to produce a diagonal
line plus a white filled triangle that is clipped.
It works fine and produces this image
/* Bring in gd library functions */ #include "gd.h" /* Bring in standard I/O so we can output the GIF to a file */ #includeint main() { /* Declare the image */ gdImagePtr im; /* Declare an output file */ FILE *out; /* Declare color indexes */ int black; int white; int red; /* Points of polygon */ gdPoint points[3]; /* 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); /* Allocate the color red. */ red = gdImageColorAllocate(im, 255, 0, 0); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); /* Draw a triangle. */ points[0].x = 50; points[0].y = 0; points[1].x = 99; points[1].y = 99; points[2].x = 0; points[2].y = 99; /* Paint it in white */ gdImageFilledPolygon(im, points, 3, white); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ out = fopen("test.gif", "w"); /* Output the image to the disk file. */ gdImageGif(im, out); /* Close the file. */ fclose(out); /* Destroy the image in memory. */ gdImageDestroy(im); }
The following demonstration program is supposed to produce a diagonal
line plus a red filled rectangle that is clipped.
It does not work correctly.
It produces this image
/* Bring in gd library functions */ #include "gd.h" /* Bring in standard I/O so we can output the GIF to a file */ #includeint main() { /* Declare the image */ gdImagePtr im; /* Declare an output file */ FILE *out; /* Declare color indexes */ int black; int white; int red; /* Points of polygon */ gdPoint points[4]; /* 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); /* Allocate the color red. */ red = gdImageColorAllocate(im, 255, 0, 0); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); /* Draw a triangle. */ points[0].x = 40; points[0].y = 10; points[1].x = 40; points[1].y = 40; points[2].x = 90; points[2].y = 40; points[3].x = 90; points[3].y = 10; /* Paint it in white */ gdImageFilledPolygon(im, points, 4, red); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ out = fopen("test.gif", "w"); /* Output the image to the disk file. */ gdImageGif(im, out); /* Close the file. */ fclose(out); /* Destroy the image in memory. */ gdImageDestroy(im); }