Mercurial > resize-gd
annotate resize-gd.c @ 4:aa24986b8969
replaces simple Makefile with a good one
author | meillo@marmaro.de |
---|---|
date | Sat, 14 Jun 2008 12:00:23 +0200 |
parents | 35a50e57b6f5 |
children | 8e2804fe30bc |
rev | line source |
---|---|
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
1 /* |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
2 * compile with: gcc -lgd -lpng -lz -ljpeg -lm resize-gd.c |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
3 * build-depends: libgd2-noxpm-dev | libgd2-dev |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
4 * depends: libgd2-noxpm | libgd2-xpm |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
5 * |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
6 * |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
7 * |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
8 * http://www.libgd.org/ImageCreation |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
9 * http://cpan.uwinnipeg.ca/htdocs/Image-Resize/Image/Resize.pm.html |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
10 * http://netpbm.sourceforge.net/ |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
11 * |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
12 */ |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
13 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
14 #include <stdio.h> |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
15 #include <stdlib.h> /* for atoi() */ |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
16 #include <string.h> |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
17 #include <ctype.h> |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
18 #include "gd.h" /* Bring in the gd library functions */ |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
19 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
20 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
21 enum { |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
22 Png, |
3 | 23 Jpg |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
24 }; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
25 |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
26 struct size { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
27 int w; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
28 int h; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
29 }; |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
30 |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
31 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
32 void |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
33 usage() { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
34 puts("\ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
35 usage: resize-gd <size> <imagefiles> [...]\n\ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
36 (keeps aspect ratio, does not enlarge images)\n\ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
37 resize-gd <width>x<height> <imagefiles> [...]\n\ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
38 (resizes to that size, enlarges if needed)\n\ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
39 "); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
40 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
41 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
42 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
43 struct size |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
44 calcsize(struct size opt, struct size img, int enlarge) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
45 struct size result; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
46 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
47 if (opt.h <= 0) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
48 /* keep aspect ratio */ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
49 if (!enlarge && opt.w > img.w && opt.w > img.h) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
50 opt.w = (img.w > img.h) ? img.w : img.h; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
51 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
52 if (img.w > img.h) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
53 result.w = opt.w; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
54 result.h = opt.w * (1.0 * img.h / img.w); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
55 } else { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
56 result.h = opt.w; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
57 result.w = opt.w * (1.0 * img.w / img.h); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
58 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
59 } else { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
60 result = opt; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
61 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
62 return result; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
63 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
64 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
65 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
66 int |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
67 validsize(char* sp) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
68 while (isdigit(*sp)) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
69 sp++; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
70 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
71 if (*sp == 'x' && isdigit(*(sp+1))) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
72 sp++; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
73 while (isdigit(*sp)) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
74 sp++; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
75 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
76 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
77 if (*sp != '\0') { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
78 return 0; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
79 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
80 return 1; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
81 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
82 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
83 |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
84 int |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
85 main(int argc, char* argv[]) { |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
86 int i; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
87 int type; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
88 gdImagePtr im_in; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
89 gdImagePtr im_out; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
90 FILE* in; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
91 FILE* out; |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
92 char* c; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
93 struct size sizeopt, sizeimg, sizedest; |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
94 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
95 if (argc < 3) { |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
96 usage(); |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
97 exit(1); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
98 } |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
99 |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
100 if (!validsize(argv[1])) { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
101 fprintf(stderr, "Invalid form of size. Has to be <size> or <width>x<height>.\n"); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
102 usage(); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
103 exit(3); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
104 } |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
105 |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
106 /* parse width and height */ |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
107 sizeopt.w = atoi(argv[1]); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
108 c = strstr(argv[1], "x"); |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
109 if (c && c[1] != '\0') { |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
110 sizeopt.h = atoi(c + 1); |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
111 } else { |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
112 sizeopt.h = -1; /* keep aspect ratio */ |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
113 } |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
114 |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
115 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
116 /* process images */ |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
117 for (i = 2; i < argc; i++) { |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
118 printf("processing file '%s'\n", argv[i]); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
119 |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
120 if (strcmp(argv[i]+strlen(argv[i])-4, ".png") == 0) { |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
121 type = Png; |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
122 } else if (strcmp(argv[i]+strlen(argv[i])-4, ".jpg") == 0) { |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
123 type = Jpg; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
124 } else { |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
125 fprintf(stderr, "'%s' has unknown filetype. Filename must end with (lowercase) '.png' or '.jpg'.\n", argv[i]); |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
126 continue; |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
127 } |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
128 /* load image */ |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
129 in = fopen(argv[i], "rb"); |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
130 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
131 if (type == Png) { |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
132 im_in = gdImageCreateFromPng(in); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
133 } else if (type == Jpg) { |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
134 im_in = gdImageCreateFromJpeg(in); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
135 } |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
136 /* |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
137 if ((im_in = gdImageCreateFromPng(in)) != NULL) { |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
138 type = Png; |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
139 } else if ((im_in = gdImageCreateFromJpeg(in)) != NULL) { |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
140 type = Jpg; |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
141 } else { |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
142 fprintf(stderr, "'%s' has unknown filetype. Filename must end with (lowercase) '.png' or '.jpg'.\n", argv[i]); |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
143 continue; |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
144 } |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
145 */ |
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
146 |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
147 fclose(in); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
148 |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
149 /* calculate target size */ |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
150 sizeimg.w = im_in->sx; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
151 sizeimg.h = im_in->sy; |
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
152 sizedest = calcsize(sizeopt, sizeimg, 0); |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
153 |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
154 /* copy-resize the image */ |
2
8e71b54b6e1e
made separate functions for calcsize and usage; pictures are not enlarged by default
meillo@marmaro.de
parents:
1
diff
changeset
|
155 im_out = gdImageCreateTrueColor(sizedest.w, sizedest.h); |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
156 gdImageCopyResampled(im_out, im_in, 0, 0, 0, 0, im_out->sx, im_out->sy, im_in->sx, im_in->sy); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
157 |
1
7a8f72b27dc3
added keep aspect ratio; validated size
meillo@localhost.localdomain
parents:
0
diff
changeset
|
158 /* write image */ |
0
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
159 out = fopen(argv[i], "wb"); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
160 if (type == Png) { |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
161 gdImagePng(im_out, out); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
162 } else if (type == Jpg) { |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
163 gdImageJpeg(im_out, out, -1); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
164 } |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
165 fclose(out); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
166 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
167 gdImageDestroy(im_in); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
168 gdImageDestroy(im_out); |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
169 } |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
170 |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
171 return 0; |
8c94239b3b3f
initial commit (provides basic funcionality)
meillo@localhost.localdomain
parents:
diff
changeset
|
172 } |