php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gddemo.c
Go to the documentation of this file.
1#include <stdio.h>
2#include "gd.h"
3#include "gdfontg.h"
4#include "gdfonts.h"
5
6int
7main (void)
8{
9 /* Input and output files */
10 FILE *in;
11 FILE *out;
12
13 /* Input and output images */
14 gdImagePtr im_in = 0, im_out = 0;
15
16 /* Brush image */
17 gdImagePtr brush;
18
19 /* Color indexes */
20 int white;
21 int blue;
22 int red;
23 int green;
24
25 /* Points for polygon */
26 gdPoint points[3];
27
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);
32
33 /* Set transparent color. */
34 gdImageColorTransparent (im_out, white);
35
36 /* Try to load demoin.png and paste part of it into the
37 output image. */
38 in = fopen ("demoin.png", "rb");
39 if (!in)
40 {
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");
44 im_in = 0;
45 }
46 else
47 {
48 im_in = gdImageCreateFromPng (in);
49 fclose (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);
53 }
54 red = gdImageColorAllocate (im_out, 255, 0, 0);
55 green = gdImageColorAllocate (im_out, 0, 255, 0);
56 blue = gdImageColorAllocate (im_out, 0, 0, 255);
57 /* Rectangle */
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);
62 /* Circle */
63 gdImageArc (im_out, 128, 128, 60, 20, 0, 720, blue);
64 /* Arc */
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);
69 /* Polygon */
70 points[0].x = 64;
71 points[0].y = 0;
72 points[1].x = 0;
73 points[1].y = 128;
74 points[2].x = 128;
75 points[2].y = 128;
76 gdImageFilledPolygon (im_out, points, 3, green);
77 /* Brush. A fairly wild example also involving a line style! */
78 if (im_in)
79 {
80 int style[8];
81 brush = gdImageCreateTrueColor (16, 16);
82 gdImageCopyResized (brush, im_in,
83 0, 0, 0, 0,
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. */
89 style[0] = 0;
90 style[1] = 0;
91 style[2] = 0;
92 style[3] = 0;
93 style[4] = 0;
94 style[5] = 0;
95 style[6] = 0;
96 style[7] = 1;
97 gdImageSetStyle (im_out, style, 8);
98 /* Draw the styled, brushed line */
99 gdImageLine (im_out, 0, 255, 255, 0, gdStyledBrushed);
100 }
101 /* Text */
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");
109 /* Write PNG */
110 gdImagePng (im_out, out);
111 fclose (out);
112 gdImageDestroy (im_out);
113 if (im_in)
114 {
115 gdImageDestroy (im_in);
116 }
117 return 0;
118}
fprintf($stream, string $format, mixed ... $values)
fclose($stream)
fopen(string $filename, string $mode, bool $use_include_path=false, $context=null)
void gdImagePng(gdImagePtr im, FILE *out)
#define gdImageSY(im)
Definition gd.h:769
#define gdStyledBrushed
Definition gd.h:328
#define gdImageSX(im)
Definition gd.h:768
gdImagePtr gdImageCreateFromPng(FILE *fd)
gdImage * gdImagePtr
Definition gd.h:248
int main(void)
Definition gddemo.c:7
gdFontPtr gdFontGiant
Definition gdfontg.c:4382
gdFontPtr gdFontSmall
Definition gdfonts.c:3869
void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c)
Definition gd.c:2730
void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
Definition gd.c:2487
void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color)
Definition gd.c:1573
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush)
Definition gd.c:2874
void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Definition gd.c:1096
void gdImageDestroy(gdImagePtr im)
Definition gd.c:247
void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
Definition gd.c:1645
void gdImageSetStyle(gdImagePtr im, int *style, int noOfPixels)
Definition gd.c:2855
void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color)
Definition gd.c:1584
int gdImageColorAllocate(gdImagePtr im, int r, int g, int b)
Definition gd.c:489
void gdImageFill(gdImagePtr im, int x, int y, int nc)
Definition gd.c:1970
void gdImageInterlace(gdImagePtr im, int interlaceArg)
Definition gd.c:2915
gdImagePtr gdImageCreateTrueColor(int sx, int sy)
Definition gd.c:195
void gdImageColorTransparent(gdImagePtr im, int color)
Definition gd.c:606
Definition gd.h:503
int x
Definition gd.h:504
int y
Definition gd.h:504
out($f, $s)