Back to index

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