Back to index

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