Back to index

php5  5.3.10
gdtopng.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include "gd.h"
00003 
00004 /* A short program which converts a .png file into a .gd file, for
00005    your convenience in creating images on the fly from a
00006    basis image that must be loaded quickly. The .gd format
00007    is not intended to be a general-purpose format. */
00008 
00009 int
00010 main (int argc, char **argv)
00011 {
00012   gdImagePtr im;
00013   FILE *in, *out;
00014   if (argc != 3)
00015     {
00016       fprintf (stderr, "Usage: gdtopng filename.gd filename.png\n");
00017       exit (1);
00018     }
00019   in = fopen (argv[1], "rb");
00020   if (!in)
00021     {
00022       fprintf (stderr, "Input file does not exist!\n");
00023       exit (1);
00024     }
00025   im = gdImageCreateFromGd (in);
00026   fclose (in);
00027   if (!im)
00028     {
00029       fprintf (stderr, "Input is not in GD format!\n");
00030       exit (1);
00031     }
00032   out = fopen (argv[2], "wb");
00033   if (!out)
00034     {
00035       fprintf (stderr, "Output file cannot be written to!\n");
00036       gdImageDestroy (im);
00037       exit (1);
00038     }
00039   gdImagePng (im, out);
00040   fclose (out);
00041   gdImageDestroy (im);
00042 
00043   return 0;
00044 }