8 /* Input and output files */
12 /* Input and output images */
13 gdImagePtr im_in, im_out;
24 /* Points for polygon */
27 /* Create output image, 128 by 128 pixels. */
28 im_out = gdImageCreate(128, 128);
30 /* First color allocated is background. */
31 white = gdImageColorAllocate(im_out, 255, 255, 255);
33 /* Set transparent color. */
34 gdImageColorTransparent(im_out, white);
36 /* Try to load demoin.gif and paste part of it into the
39 in = fopen("demoin.gif", "rb");
41 fprintf(stderr, "Can't load source image; this demo\n");
42 fprintf(stderr, "is much more impressive if demoin.gif\n");
43 fprintf(stderr, "is available.\n");
46 im_in = gdImageCreateFromGif(in);
48 /* Now copy, and magnify as we do so */
49 gdImageCopyResized(im_out, im_in,
50 16, 16, 0, 0, 96, 96, 127, 127);
52 red = gdImageColorAllocate(im_out, 255, 0, 0);
53 green = gdImageColorAllocate(im_out, 0, 255, 0);
54 blue = gdImageColorAllocate(im_out, 0, 0, 255);
56 gdImageLine(im_out, 8, 8, 120, 8, green);
57 gdImageLine(im_out, 120, 8, 120, 120, green);
58 gdImageLine(im_out, 120, 120, 8, 120, green);
59 gdImageLine(im_out, 8, 120, 8, 8, green);
61 gdImageArc(im_out, 64, 64, 30, 10, 0, 360, blue);
63 gdImageArc(im_out, 64, 64, 20, 20, 45, 135, blue);
65 gdImageFill(im_out, 4, 4, blue);
73 gdImageFilledPolygon(im_out, points, 3, green);
74 /* Brush. A fairly wild example also involving a line style! */
77 brush = gdImageCreate(8, 8);
78 gdImageCopyResized(brush, im_in,
80 gdImageSX(brush), gdImageSY(brush),
81 gdImageSX(im_in), gdImageSY(im_in));
82 gdImageSetBrush(im_out, brush);
83 /* With a style, so they won't overprint each other.
84 Normally, they would, yielding a fat-brush effect. */
93 gdImageSetStyle(im_out, style, 8);
94 /* Draw the styled, brushed line */
95 gdImageLine(im_out, 0, 127, 127, 0, gdStyledBrushed);
98 gdImageString(im_out, gdFontGiant, 16, 16, "hi", red);
99 gdImageStringUp(im_out, gdFontSmall, 32, 32, "hi", red);
100 /* Make output image interlaced (allows "fade in" in some viewers,
101 and in the latest web browsers) */
102 gdImageInterlace(im_out, 1);
103 out = fopen("demoout.gif", "wb");
105 gdImageGif(im_out, out);
107 gdImageDestroy(im_out);
109 gdImageDestroy(im_in);