1

I'm trying to convert(compress) a bunch of JPEG images using imagemagick command mogrify, keeping the original file in the same directory. I'm typing in terminal window : mogrify -quality 25% *.JPEG con-%002d.JPEG then I get the error : mogrify: unable to open image `con-%002d.JPEG': No such file or directory @ error/blob.c/OpenBlob/2712. How can I solve this error? I have run : identify -verbose * | grep Format and the result is for all files : Format: JPEG (Joint Photographic Experts Group JFIF format) exif:thumbnail:JPEGInterchangeFormat: 10718 exif:thumbnail:JPEGInterchangeFormatLength: 8223

My system is Xubuntu 16.04, I appreciate some help, thanks Vladi.

2 Answers2

2

Per the man page mogrify does not take an output option, it simply overwrites the input file unless the format is changed (the same name is used up to the file extension).

Try this using convert instead.

#!/bin/bash
n=1
for i in *.JPEG; do 
    convert "$i" -format jpg -quality '25%' $(printf con-%03d.JPEG $n)
    n=$((n+1))
done

JPEG vs jpg

I mogrified the same image twice

$ mogrify -format JPEG b.jpg
$ mogrify -format jpg b.jpg

Then

$ diff -u <(identify -verbose b.jpg ) <(identify -verbose b.JPEG)
--- /dev/fd/63  2018-09-29 14:42:27.506462707 -0400
+++ /dev/fd/62  2018-09-29 14:42:27.510462929 -0400
@@ -1 +1 @@
-Image: b.jpg
+Image: b.JPEG
@@ -71,2 +71,2 @@
-    date:create: 2018-09-29T14:37:11-04:00
-    date:modify: 2018-09-29T14:37:11-04:00
+    date:create: 2018-09-29T14:37:03-04:00
+    date:modify: 2018-09-29T14:37:03-04:00
@@ -77 +77 @@
-    filename: b.jpg
+    filename: b.JPEG
0

Use -write

mogrify -set filename:name '%t_q%Q' -quality 30 -write '%[filename:name].jpg' *.jpg

Above command will write the converted image to a new name: converting name.jpg to name_q30.jpg, name1.jpg to name1_q30.jpg. Keeping your old files safe.

For other percentage escape metadata options, see the docs

Janghou
  • 111