Annotation of embedaddon/php/ext/gd/libgd/gdparttopng.c, revision 1.1

1.1     ! misho       1: #include <stdio.h>
        !             2: #include <stdlib.h>            /* For atoi */
        !             3: #include "gd.h"
        !             4: 
        !             5: /* A short program which converts a .png file into a .gd file, for
        !             6:    your convenience in creating images on the fly from a
        !             7:    basis image that must be loaded quickly. The .gd format
        !             8:    is not intended to be a general-purpose format. */
        !             9: 
        !            10: int
        !            11: main (int argc, char **argv)
        !            12: {
        !            13:   gdImagePtr im;
        !            14:   FILE *in, *out;
        !            15:   int x, y, w, h;
        !            16: 
        !            17:   if (argc != 7)
        !            18:     {
        !            19:       fprintf (stderr, "Usage: gdparttopng filename.gd filename.png x y w h\n");
        !            20:       exit (1);
        !            21:     }
        !            22:   in = fopen (argv[1], "rb");
        !            23:   if (!in)
        !            24:     {
        !            25:       fprintf (stderr, "Input file does not exist!\n");
        !            26:       exit (1);
        !            27:     }
        !            28: 
        !            29:   x = atoi (argv[3]);
        !            30:   y = atoi (argv[4]);
        !            31:   w = atoi (argv[5]);
        !            32:   h = atoi (argv[6]);
        !            33: 
        !            34:   printf ("Extracting from (%d, %d), size is %dx%d\n", x, y, w, h);
        !            35: 
        !            36:   im = gdImageCreateFromGd2Part (in, x, y, w, h);
        !            37:   fclose (in);
        !            38:   if (!im)
        !            39:     {
        !            40:       fprintf (stderr, "Input is not in GD2 format!\n");
        !            41:       exit (1);
        !            42:     }
        !            43:   out = fopen (argv[2], "wb");
        !            44:   if (!out)
        !            45:     {
        !            46:       fprintf (stderr, "Output file cannot be written to!\n");
        !            47:       gdImageDestroy (im);
        !            48:       exit (1);
        !            49:     }
        !            50: #ifdef HAVE_LIBPNG
        !            51:   gdImagePng (im, out);
        !            52: #else
        !            53:   fprintf(stderr, "No PNG library support.\n");
        !            54: #endif
        !            55:   fclose (out);
        !            56:   gdImageDestroy (im);
        !            57: 
        !            58:   return 0;
        !            59: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>