Change quality of lots of images by one click :: linux
August 21, 2009 | linux, toolsauthor: Karol Zielinski | comments: 1 | views: 718
Tags: compress, convert, image, jpg, linux, multi-file, multi-image, perl, quality
Did you ever try to change quality of lots of images? If you ever tried to put some images to your website – propably you did. How you can do it? Via Gimp, Photoshop, Paint, isn’t? Sure, you can. However… it takes so much time.
If you like to waste your time for boring things… you can always open each image via Gimp, press Ctrl+Shift+S, change quality by slider, etc. Yeah, that’s right – you can.
However… for all of you who want to spend free time doing much more interesting things, I recommend to use simple perl script.
Try to put this line into your linux console:
perl -e 'for (glob "*.jpg") { $img = $_; s/(....)$/$1_changed/; qx "convert $img -quality 80% $_"; }'
this line of code will reduce quality of all JPG files in our directory to 80% and save images with lower quality to files with suffix ‘_changed’.
and now… try to put this line of code:
perl -e 'for (glob "*.jpg") { $img = $_; s/(....)$/$1/; qx "convert $img -quality 80% $_"; }'
this line of code will reduce quality of all jpg files in our directory to 80% and replace original JPG files.
all you need to have is:
much easier, isn’t it?
Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.
August 22, 2009, 11:04 pm
You can accomplish the goal of your first example without perl:
for f in *.jpg; do convert $f -quality 80% lowqual-$f; done
I prefer to save them in a new directory instead of messing with the filenames:
mkdir lowqual
for f in *.jpg; do convert $f -quality 80% lowqual/$f; done
When you don’t need the originals, just use mogrify:
mogrify -quality 80% *.jpg