Mercurial > resize-gd
changeset 5:8e2804fe30bc
skipps now too small images; added --version and --help
author | meillo@marmaro.de |
---|---|
date | Sat, 14 Jun 2008 12:18:06 +0200 |
parents | aa24986b8969 |
children | e020f26c2c6a |
files | resize-gd.c |
diffstat | 1 files changed, 28 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ctype.h> #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 <size> <imagefiles> [...]\n\ + printf("\ +usage: %s <size> <imagefiles> [...]\n\ (keeps aspect ratio, does not enlarge images)\n\ - resize-gd <width>x<height> <imagefiles> [...]\n\ + %s <width>x<height> <imagefiles> [...]\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 <size> or <width>x<height>.\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);