From 7979f76dcd5d5e2340956f6ec3b9009e64648fc1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Sep 2012 15:20:47 +0200 Subject: Fix EXIF orientation tag after lossless rotate --- src/imlib.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/imlib.c') diff --git a/src/imlib.c b/src/imlib.c index b3abc8a..f247bf7 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -1137,6 +1137,7 @@ void feh_edit_inplace_lossless(winwidget w, int op) int len = strlen(filename) + 1; char *file_str = emalloc(len); int pid, status; + int devnull = -1; char op_name[] = "rotate"; /* message */ char op_op[] = "-rotate"; /* jpegtran option */ char op_value[] = "horizontal"; /* jpegtran option's value */ @@ -1156,14 +1157,16 @@ void feh_edit_inplace_lossless(winwidget w, int op) if ((pid = fork()) < 0) { im_weprintf(w, "lossless %s: fork failed:", op_name); exit(1); - } else if (pid == 0) { + } + else if (pid == 0) { execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value, "-outfile", file_str, file_str, NULL); im_weprintf(w, "lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name); exit(1); - } else { + } + else { waitpid(pid, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { @@ -1176,6 +1179,31 @@ void feh_edit_inplace_lossless(winwidget w, int op) return; } } + if ((pid = fork()) < 0) { + im_weprintf(w, "lossless %s: cannot fix rotation: fork:", op_name); + exit(1); + } + else if (pid == 0) { + + /* discard normal output */ + devnull = open("/dev/null", O_WRONLY); + dup2(devnull, 1); + + execlp("jpegexiforient", "jpegexiforient", "-1", file_str, NULL); + im_weprintf(w, "lossless %s: Failed to exec jpegexiforient:", op_name); + exit(1); + } + else { + waitpid(pid, &status, 0); + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + im_weprintf(w, + "lossless %s: Got exitcode %d from jpegexiforient", + status >> 8); + free(file_str); + return; + } + } free(file_str); } -- cgit v1.2.3