# HG changeset patch # User meillo@marmaro.de # Date 1213438686 -7200 # Node ID 8e2804fe30bc040dc140eafc140d4c7e5e8694b2 # Parent aa24986b89698bf2f5c96b48acbc910bea2c9b04 skipps now too small images; added --version and --help diff -r aa24986b8969 -r 8e2804fe30bc resize-gd.c --- a/resize-gd.c Sat Jun 14 12:00:23 2008 +0200 +++ b/resize-gd.c Sat Jun 14 12:18:06 2008 +0200 @@ -17,6 +17,8 @@ #include #include "gd.h" /* Bring in the gd library functions */ +#define PROGRAM "resize-gd" +#define VERSION "0.1" enum { Png, @@ -30,13 +32,19 @@ void +version() { + printf("%s version: %s\n", PROGRAM, VERSION); +} + + +void usage() { - puts("\ -usage: resize-gd [...]\n\ + printf("\ +usage: %s [...]\n\ (keeps aspect ratio, does not enlarge images)\n\ - resize-gd x [...]\n\ + %s x [...]\n\ (resizes to that size, enlarges if needed)\n\ -"); +", PROGRAM, PROGRAM); } @@ -92,6 +100,15 @@ char* c; struct size sizeopt, sizeimg, sizedest; + if (argc == 2 && strcmp(argv[1], "--version") == 0) { + version(); + exit(0); + } + if (argc == 2 && strcmp(argv[1], "--help") == 0) { + version(); + usage(); + exit(0); + } if (argc < 3) { usage(); exit(1); @@ -100,7 +117,7 @@ if (!validsize(argv[1])) { fprintf(stderr, "Invalid form of size. Has to be or x.\n"); usage(); - exit(3); + exit(2); } /* parse width and height */ @@ -151,6 +168,12 @@ sizeimg.h = im_in->sy; sizedest = calcsize(sizeopt, sizeimg, 0); + /* skip images that dont need to be resized */ + if (sizedest.w == sizeimg.w && sizedest.h == sizeimg.h) { + gdImageDestroy(im_in); + continue; + } + /* copy-resize the image */ im_out = gdImageCreateTrueColor(sizedest.w, sizedest.h); gdImageCopyResampled(im_out, im_in, 0, 0, 0, 0, im_out->sx, im_out->sy, im_in->sx, im_in->sy);