php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gdparttopng.c
Go to the documentation of this file.
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
10int
11main (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}
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
void gdImagePng(gdImagePtr im, FILE *out)
gdImage * gdImagePtr
Definition gd.h:248
int main(void)
Definition gddemo.c:7
void gdImageDestroy(gdImagePtr im)
Definition gd.c:247
exit(string|int $status=0)
out($f, $s)