php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gd2time.c
Go to the documentation of this file.
1
2#include <stdio.h>
3#include <stdlib.h> /* for atoi */
4#include <time.h> /* For time */
5#include "gd.h"
6
7/* A short program which converts a .png file into a .gd file, for
8 your convenience in creating images on the fly from a
9 basis image that must be loaded quickly. The .gd format
10 is not intended to be a general-purpose format. */
11
12int
13main (int argc, char **argv)
14{
15 gdImagePtr im;
16 FILE *in;
17 int x, y, w, h;
18 int c;
19 int i;
20 int t0;
21
22 if (argc != 7)
23 {
24 fprintf (stderr, "Usage: gd2time filename.gd count x y w h\n");
25 exit (1);
26 }
27
28 c = atoi (argv[2]);
29 x = atoi (argv[3]);
30 y = atoi (argv[4]);
31 w = atoi (argv[5]);
32 h = atoi (argv[6]);
33
34 printf ("Extracting %d times from (%d, %d), size is %dx%d\n", c, x, y, w, h);
35
36 t0 = time (0);
37 for (i = 0; i < c; i++)
38 {
39 in = fopen (argv[1], "rb");
40 if (!in)
41 {
42 fprintf (stderr, "Input file does not exist!\n");
43 exit (1);
44 }
45
46 im = gdImageCreateFromGd2Part (in, x, y, w, h);
47 fclose (in);
48
49 if (!im)
50 {
51 fprintf (stderr, "Error reading source file!\n");
52 exit (1);
53 }
54 gdImageDestroy (im);
55 };
56 t0 = time (0) - t0;
57 printf ("%d seconds to extract (& destroy) %d times\n", t0, c);
58
59 return 0;
60}
fprintf($stream, string $format, mixed ... $values)
printf(string $format, mixed ... $values)
fclose($stream)
fopen(string $filename, string $mode, bool $use_include_path=false, $context=null)
gdImagePtr gdImageCreateFromGd2Part(FILE *in, int srcx, int srcy, int w, int h)
Definition gd_gd2.c:422
gdImage * gdImagePtr
Definition gd.h:248
int main(void)
Definition gddemo.c:7
void gdImageDestroy(gdImagePtr im)
Definition gd.c:247
time()
exit(string|int $status=0)