Debian Codegraph @

examples/gif.c

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <gd.h>
4
5 int main(void)
6 {
7 int i;
8 FILE * out;
9
10 gdImagePtr im;
11 gdImagePtr prev =NULL;
12 int black;
13
14 im = gdImageCreate(100, 100);
15 if (!im) {
16 fprintf(stderr, "can't create image");
17 return 1;
18 }
19
20 out = fopen("anim.gif", "wb");
21 if (!out) {
22 fprintf(stderr, "can't create file %s", "anim.gif");
23 return 1;
24 }
25
26 gdImageColorAllocate(im, 255, 255, 255); /* allocate white as side effect */
27 gdImageGifAnimBegin(im, out, 1, -1);
28
29 for(i = 0; i < 20; i++) {
30 int r,g,b;
31 im = gdImageCreate(100, 100);
32 r = rand() % 255;
33 g = rand() % 255;
34 b = rand() % 255;
35
36 gdImageColorAllocate(im, 255, 255, 255); /* allocate white as side effect */
37 black = gdImageColorAllocate(im, r, g, b);
38 printf("(%i, %i, %i)\n",r, g, b);
39 gdImageFilledRectangle(im, rand() % 100, rand() % 100, rand() % 100, rand() % 100, black);
40 gdImageGifAnimAdd(im, out, 1, 0, 0, 10, 1, prev);
41
42 if(prev) {
43 gdImageDestroy(prev);
44 }
45 prev = im;
46 }
47
48 gdImageGifAnimEnd(out);
49 fclose(out);
50
51 return 0;
52 }