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