summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2014-03-12 17:02:39 +0100
committerRemi Collet <fedora@famillecollet.com>2014-03-12 17:02:39 +0100
commit1de3b800523adaa63ab2ce88cfb8c5569b269318 (patch)
tree718fee376e4275e0ff05f6b58af71b3d29c0170b /examples
parent5b42b1178c37ffd30c9a15733058656be0277da0 (diff)
downloadlibgd-1de3b800523adaa63ab2ce88cfb8c5569b269318.tar.gz
new example "resize"
Diffstat (limited to 'examples')
-rw-r--r--examples/resize.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/examples/resize.c b/examples/resize.c
new file mode 100644
index 0000000..84543cd
--- /dev/null
+++ b/examples/resize.c
@@ -0,0 +1,59 @@
+#include "gd.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (int argc, char *argv[]) {
+ FILE *fp;
+ gdImagePtr in, out;
+ int w, h;
+
+ /* Help */
+ if (argc<=4) {
+ printf("%s input.jpg output.jpg width height\n", argv[0]);
+ return 1;
+ }
+
+ /* Size */
+ w = atoi(argv[3]);
+ h = atoi(argv[4]);
+ if (w<=0 || h<=0) {
+ fprintf(stderr, "Bad size %dx%d\n", h, w);
+ return 2;
+ }
+
+ /* Input */
+ fp = fopen(argv[1], "rb");
+ if (!fp) {
+ fprintf(stderr, "Can't read image %s\n", argv[1]);
+ return 3;
+ }
+ in = gdImageCreateFromJpeg(fp);
+ fclose(fp);
+ if (!in) {
+ fprintf(stderr, "Can't create image from %s\n", argv[1]);
+ return 4;
+ }
+
+ /* Resize */
+ gdImageSetInterpolationMethod(in, GD_BILINEAR_FIXED);
+ out = gdImageScale(in, w, h);
+ if (!out) {
+ fprintf(stderr, "gdImageScale fails\n");
+ return 5;
+ }
+
+ /* Output */
+ fp = fopen(argv[2], "wb");
+ if (!fp) {
+ fprintf(stderr, "Can't save image %s\n", argv[2]);
+ return 6;
+ }
+ gdImageJpeg(out, fp, 90);
+ fclose(fp);
+
+ /* Cleanups */
+ gdImageDestroy(in);
+ gdImageDestroy(out);
+
+ return 0;
+} \ No newline at end of file