changeset 14:6f5c3a02e4d5

filename suffix is now detected in lower or upper case letters
author meillo@marmaro.de
date Sun, 15 Jun 2008 15:50:59 +0200
parents c4834b4f4b54
children c50716420346
files resize-gd.1 resize-gd.c
diffstat 2 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/resize-gd.1	Sat Jun 14 19:14:27 2008 +0200
+++ b/resize-gd.1	Sun Jun 15 15:50:59 2008 +0200
@@ -1,4 +1,4 @@
-.TH RESIZE\-GD 1 "resize\-gd\-0.1" "2008\-06\-14" "resize\-gd"
+.TH RESIZE\-GD 1 "resize\-gd\-0.2" "2008\-06\-15" "resize\-gd"
 
 .SH NAME
 resize\-gd \- resizes images using the gd library
@@ -15,7 +15,7 @@
 .PP
 If <width>x<height> ist given, the images are resized to match that dimensions. The images probably get stretched and enlarged.
 .PP
-Only JPEG and PNG files are supported. The filetype is detected by the filename suffix which has to be either `.jpg' or `.png' (in lowercase letters).
+Only JPEG and PNG files are supported. The filetype is detected by the filename suffix which has to be `.jpg', `.jpeg' or `.png'.
 Unsupported files get skipped.
 .PP
 This program is meant to be a small(er) alternative to the
--- a/resize-gd.c	Sat Jun 14 19:14:27 2008 +0200
+++ b/resize-gd.c	Sun Jun 15 15:50:59 2008 +0200
@@ -118,7 +118,7 @@
 
 	/* parse width and height */
 	sizeopt.w = atoi(argv[1]);
-	c = strstr(argv[1], "x");
+	c = strchr(argv[1], 'x');
 	if (c && c[1] != '\0') {
 		sizeopt.h = atoi(c + 1);
 	} else {
@@ -130,12 +130,13 @@
 	for (i = 2; i < argc; i++) {
 		/* printf("processing file '%s'\n", argv[i]); */
 
-		if (strcmp(argv[i]+strlen(argv[i])-4, ".png") == 0) {
+		c = strrchr(argv[i], '.');
+		if (strcmp(c, ".png") == 0 || strcmp(c, ".PNG") == 0) {
 			type = Png;
-		} else if (strcmp(argv[i]+strlen(argv[i])-4, ".jpg") == 0) {
+		} else if (strcmp(c, ".jpg") == 0 || strcmp(c, ".JPG") == 0 || strcmp(c, ".jpeg") == 0 || strcmp(c, ".JPEG") == 0) {
 			type = Jpg;
 		} else {
-			fprintf(stderr, "'%s' has unknown filetype. Filename must end with (lowercase) '.png' or '.jpg'.\n", argv[i]);
+			fprintf(stderr, "'%s' has unknown filetype. Filename must end with '.jpg', '.jpeg' or '.png'.\n", argv[i]);
 			continue;
 		}