Debian Codegraph @

examples/tiffread.c

raw
1 /*
2 * You can fetch a set of samples TIFF images here:
3 * ftp://ftp.remotesensing.org/pub/libtiff/
4 * (pics-x.y.z.tar.gz)
5 */
6
7 #include <gd.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 int main()
11 {
12 gdImagePtr im;
13 FILE *fp;
14 char path[9][2048];
15 int i;
16 char dst[2048];
17
18 sprintf(path[0], "cramps-tile.tif");
19 sprintf(path[1], "cramps.tif");
20 sprintf(path[2], "ycbcr-cat.tif");
21 sprintf(path[3], "jello.tif");
22 sprintf(path[4], "caspian.tif");
23 sprintf(path[5], "strike.tif");
24 sprintf(path[6], "off_luv24.tif");
25 sprintf(path[7], "off_l16.tif");
26 sprintf(path[8], "fax2d.tif");
27
28 for (i = 0; i < 9; i++) {
29 printf("opening %s\n", path[i]);
30 fp = fopen(path[i], "rb");
31 if (!fp) {
32 printf("failed, cannot open file\n");
33 return 1;
34 }
35
36 im = gdImageCreateFromTiff(fp);
37 fclose(fp);
38 if (!im) {
39 fprintf(stderr, "Can't load TIFF image %s\n", path[i]);
40 return 1;
41 }
42
43
44 sprintf(dst, "%i.png", i);
45
46 fp = fopen(dst, "wb");
47 if (!fp) {
48 fprintf(stderr, "Can't save png image fromtiff.png\n");
49 gdImageDestroy(im);
50 return 1;
51 }
52
53 gdImagePng(im, fp);
54 fclose(fp);
55 gdImageDestroy(im);
56 }
57 return 0;
58 }