48

If I convert my images with

convert -quality 80% *.jpg

It works, but the software changes the file names to the first one it picks. How can I keep the name or even replace the previous image with that of a lower quality.

2
  • 1
    @JimGarrison - sounds like a shell scripting question. Commented Mar 29, 2012 at 16:55
  • 1
    from the man page: > Mogrify overwrites the original image file, whereas, convert(1) writes to a different image file. Commented Jan 7, 2016 at 17:03

3 Answers 3

93

Try this instead:

mogrify -quality 80% *.jpg
0
18

convert command help:

convert input-file [options] output-file

Now a little script to convert all jpg files to 80% quality of original under current directory

for file in *.jpg; do
  convert "$file" -quality 80% "$file"
done;
3
  • 3
    Useless use of ls, as it can be shortened to for f in *jpg. And mogrify can work on multiple files at once. Commented Mar 29, 2012 at 17:02
  • 2
    @ringbearer It's not a great way of doing it. Requires another process, and fails for files with spaces. Apart from that it's a great answer.
    – Sparhawk
    Commented Jul 10, 2014 at 6:02
  • 1
    I removed subprocess (backtick), and add quotes to prevent errors Commented Jan 7, 2016 at 16:59
5

This will work for you.

convert -quality 80% '*.jpg' -set filename:original %t %[filename:original].jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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