xref: /PHP-7.4/ext/gd/libgd/pngtogd.c (revision 7a8cade3)
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: pngtogd filename.png filename.gd\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 = gdImageCreateFromPng (in);
27   fclose (in);
28   if (!im)
29     {
30       fprintf (stderr, "Input is not in PNG 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   gdImageGd (im, out);
41   fclose (out);
42   gdImageDestroy (im);
43 
44   return 0;
45 }
46