Back to index

php5  5.3.10
gd2copypal.c
Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include "gd.h"
00004 #include <stdlib.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   gdImagePtr pal;
00016   FILE *in, *out;
00017   if (argc != 3)
00018     {
00019       fprintf (stderr, "Usage: gd2copypal palettefile.gd2 filename.gd2\n");
00020       exit (1);
00021     }
00022   in = fopen (argv[1], "rb");
00023   if (!in)
00024     {
00025       fprintf (stderr, "Palette file does not exist!\n");
00026       exit (1);
00027     }
00028   pal = gdImageCreateFromGd2 (in);
00029   fclose (in);
00030   if (!pal)
00031     {
00032       fprintf (stderr, "Palette is not in GD2 format!\n");
00033       exit (1);
00034     }
00035 
00036   in = fopen (argv[2], "rb");
00037   if (!in)
00038     {
00039       fprintf (stderr, "Input file does not exist!\n");
00040       exit (1);
00041     }
00042   im = gdImageCreateFromGd2 (in);
00043   fclose (in);
00044   if (!im)
00045     {
00046       fprintf (stderr, "Input is not in GD2 format!\n");
00047       exit (1);
00048     }
00049 
00050   gdImagePaletteCopy (im, pal);
00051 
00052   out = fopen (argv[2], "wb");
00053   if (!out)
00054     {
00055       fprintf (stderr, "Output file cannot be written to!\n");
00056       gdImageDestroy (im);
00057       exit (1);
00058     }
00059   gdImageGd2 (im, out, 128, 2);
00060   fclose (out);
00061   gdImageDestroy (pal);
00062   gdImageDestroy (im);
00063 
00064   return 0;
00065 }