Back to index

php5  5.3.10
gd2time.c
Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include <stdlib.h>         /* for atoi */
00004 #include <time.h>           /* For time */
00005 #include "gd.h"
00006 
00007 /* A short program which converts a .png file into a .gd file, for
00008    your convenience in creating images on the fly from a
00009    basis image that must be loaded quickly. The .gd format
00010    is not intended to be a general-purpose format. */
00011 
00012 int
00013 main (int argc, char **argv)
00014 {
00015   gdImagePtr im;
00016   FILE *in;
00017   int x, y, w, h;
00018   int c;
00019   int i;
00020   int t0;
00021 
00022   if (argc != 7)
00023     {
00024       fprintf (stderr, "Usage: gd2time filename.gd count x y w h\n");
00025       exit (1);
00026     }
00027 
00028   c = atoi (argv[2]);
00029   x = atoi (argv[3]);
00030   y = atoi (argv[4]);
00031   w = atoi (argv[5]);
00032   h = atoi (argv[6]);
00033 
00034   printf ("Extracting %d times from (%d, %d), size is %dx%d\n", c, x, y, w, h);
00035 
00036   t0 = time (0);
00037   for (i = 0; i < c; i++)
00038     {
00039       in = fopen (argv[1], "rb");
00040       if (!in)
00041        {
00042          fprintf (stderr, "Input file does not exist!\n");
00043          exit (1);
00044        }
00045 
00046       im = gdImageCreateFromGd2Part (in, x, y, w, h);
00047       fclose (in);
00048 
00049       if (!im)
00050        {
00051          fprintf (stderr, "Error reading source file!\n");
00052          exit (1);
00053        }
00054       gdImageDestroy (im);
00055     };
00056   t0 = time (0) - t0;
00057   printf ("%d seconds to extract (& destroy) %d times\n", t0, c);
00058 
00059   return 0;
00060 }