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.

  • 1
    mogrify doesn't have an output file option: it always replaces the original files, and con-%002d.JPEG is treated as just another input file (which doesn't exist) after the *.JPEG list. – AFH Sep 28 '18 at 21:28
  • What kind of output name are you looking for? Sequential numbering? – chew socks Sep 28 '18 at 21:28
  • @chewsocks I read some where(I don't remember where) that I could compress a JPEG file given an output file name which not replace the original file. The output name could be a sequential number or something like con-001.JPEG, con-002.JPEG, con-003.JPEG, .... – vladimir pavloski Sep 28 '18 at 22:26
  • You may have been thinking of ffmpeg which does support sequential output naming. – chew socks Sep 28 '18 at 22:42
  • @chewsocks No, I'm not wrong, it is on imagemagick mogrify command. – vladimir pavloski Sep 28 '18 at 22:49

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.

for i in *.JPEG; do 
    convert "$i" -format jpg -quality '25%' $(printf con-%03d.JPEG $n)

JPEG vs jpg

I mogrified the same image twice

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


$ 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
  • OK!! That's done the job. Thanks. Can I ask what's the difference between JPEG format and jpg fomat ? The script above converts to "jpg" then the new file output is saved as ".JPEG" what's the hack? thanks – vladimir pavloski Sep 29 '18 at 7:46
  • @vladimirpavloski Good question...habit =P. I avoid capitals in my names so I always think of the format as "jpg". convert doesn't enforce file extensions (you could save JPEG as .txt) and since I was being specific I saw you liked "JPEG". – chew socks Sep 29 '18 at 18:47

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.