Back to index

php5  5.3.10
gdparttopng.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>         /* For atoi */
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   int x, y, w, h;
00016 
00017   if (argc != 7)
00018     {
00019       fprintf (stderr, "Usage: gdparttopng filename.gd filename.png x y w h\n");
00020       exit (1);
00021     }
00022   in = fopen (argv[1], "rb");
00023   if (!in)
00024     {
00025       fprintf (stderr, "Input file does not exist!\n");
00026       exit (1);
00027     }
00028 
00029   x = atoi (argv[3]);
00030   y = atoi (argv[4]);
00031   w = atoi (argv[5]);
00032   h = atoi (argv[6]);
00033 
00034   printf ("Extracting from (%d, %d), size is %dx%d\n", x, y, w, h);
00035 
00036   im = gdImageCreateFromGd2Part (in, x, y, w, h);
00037   fclose (in);
00038   if (!im)
00039     {
00040       fprintf (stderr, "Input is not in GD2 format!\n");
00041       exit (1);
00042     }
00043   out = fopen (argv[2], "wb");
00044   if (!out)
00045     {
00046       fprintf (stderr, "Output file cannot be written to!\n");
00047       gdImageDestroy (im);
00048       exit (1);
00049     }
00050 #ifdef HAVE_LIBPNG
00051   gdImagePng (im, out);
00052 #else
00053   fprintf(stderr, "No PNG library support.\n");
00054 #endif
00055   fclose (out);
00056   gdImageDestroy (im);
00057 
00058   return 0;
00059 }