9
/* Input and output files */
13
/* Input and output images */
14
gdImagePtr im_in = 0, im_out = 0;
25
/* Points for polygon */
28
/* Create output image, 256 by 256 pixels, true color. */
29
im_out = gdImageCreateTrueColor (256, 256);
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.png and paste part of it into the
38
in = fopen ("demoin.png", "rb");
41
fprintf (stderr, "Can't load source image; this demo\n");
42
fprintf (stderr, "is much more impressive if demoin.png\n");
43
fprintf (stderr, "is available.\n");
48
im_in = gdImageCreateFromPng (in);
50
/* Now copy, and magnify as we do so */
51
gdImageCopyResized (im_out, im_in,
52
32, 32, 0, 0, 192, 192, 255, 255);
54
red = gdImageColorAllocate (im_out, 255, 0, 0);
55
green = gdImageColorAllocate (im_out, 0, 255, 0);
56
blue = gdImageColorAllocate (im_out, 0, 0, 255);
58
gdImageLine (im_out, 16, 16, 240, 16, green);
59
gdImageLine (im_out, 240, 16, 240, 240, green);
60
gdImageLine (im_out, 240, 240, 16, 240, green);
61
gdImageLine (im_out, 16, 240, 16, 16, green);
63
gdImageArc (im_out, 128, 128, 60, 20, 0, 720, blue);
65
gdImageArc (im_out, 128, 128, 40, 40, 90, 270, blue);
66
/* Flood fill: doesn't do much on a continuously
67
variable tone jpeg original. */
68
gdImageFill (im_out, 8, 8, blue);
76
gdImageFilledPolygon (im_out, points, 3, green);
77
/* Brush. A fairly wild example also involving a line style! */
81
brush = gdImageCreateTrueColor (16, 16);
82
gdImageCopyResized (brush, im_in,
84
gdImageSX (brush), gdImageSY (brush),
85
gdImageSX (im_in), gdImageSY (im_in));
86
gdImageSetBrush (im_out, brush);
87
/* With a style, so they won't overprint each other.
88
Normally, they would, yielding a fat-brush effect. */
97
gdImageSetStyle (im_out, style, 8);
98
/* Draw the styled, brushed line */
99
gdImageLine (im_out, 0, 255, 255, 0, gdStyledBrushed);
102
gdImageString (im_out, gdFontGiant, 32, 32,
103
(unsigned char *) "hi", red);
104
gdImageStringUp (im_out, gdFontSmall, 64, 64,
105
(unsigned char *) "hi", red);
106
/* Make output image interlaced (progressive, in the case of JPEG) */
107
gdImageInterlace (im_out, 1);
108
out = fopen ("demoout.png", "wb");
110
gdImagePng (im_out, out);
112
gdImageDestroy (im_out);
115
gdImageDestroy (im_in);