1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "gd.h"
8 
9 /* A short program which converts a .png file into a .gd file, for
10    your convenience in creating images on the fly from a
11    basis image that must be loaded quickly. The .gd format
12    is not intended to be a general-purpose format. */
13 
14 int
main(int argc,char ** argv)15 main (int argc, char **argv)
16 {
17 	gdImagePtr im = NULL;
18 	FILE *in, *out;
19 	if (argc != 3) {
20 		fprintf (stderr, "Usage: pngtogd filename.png filename.gd\n");
21 		exit (1);
22 	}
23 	in = fopen (argv[1], "rb");
24 	if (!in) {
25 		fprintf (stderr, "Input file does not exist!\n");
26 		exit (1);
27 	}
28 	im = gdImageCreateFromPng (in);
29 	fclose (in);
30 	if (!im) {
31 		fprintf (stderr, "Input is not in PNG format!\n");
32 		exit (1);
33 	}
34 	out = fopen (argv[2], "wb");
35 	if (!out) {
36 		fprintf (stderr, "Output file cannot be written to!\n");
37 		gdImageDestroy (im);
38 		exit (1);
39 	}
40 	gdImageGd (im, out);
41 	fclose (out);
42 	gdImageDestroy (im);
43 
44 	return 0;
45 }
46