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