using imagemagic Convert batch operation takes too much time versus Gimp. How to execute per file in batch mode?

Viewed 33

Using imagemagic Convert batch operation takes too much time versus Gimp. How to execute per file in batch mode?

The following command can be executed to bacth convert 200+ image files. However, Convert / imagemagic creates tmp files for all images and then apply whatever process you gave to it eg. rotation.

 convert '*.jpg' -set filename:fn '%[basename]' -units PixelsPerInch  -rotate -90  -density 300 -quality 95  -resize 28% '%[filename:fn].jpg'

This means that it may consume a lot of memory / temporary disk size and it takes too much time. Now it is running more than 10+ minutes and not finished yet.

In comparison, GIMP -in batch mode- that makes operations per file (rotate, finish, next, rotate, finish, next etc.), it takes much less time (2-3 minutes).

I think GIMP uses imagemagick convert.

How can I run convert (in batch mode) in linux terminal and make operation PER FILE and not PER ALL FILES?

many files from imagemagicjk convert

2 Answers

You can also use parallel to loop over your files, eg.:

parallel \
    convert {} -resize 28% -rotate -90 -quality 95 copy_{} \
    ::: *.jpg

(you don't need density, and its faster to shrink before rotate)

That'll run the convert commands in parallel. By default it'll use as many processes as you have cores. The {} is substituted for a filename when launching a command. You should get a nice speedup.

I tried a quick benchmark with a 10,000 x 10,000 pixel jpeg:

$ for i in {1..200}; do cp ~/wtc.jpg $i.jpg; done
$ /usr/bin/time -f %M:%e parallel convert {} -resize 28% -rotate -90 -quality 95 copy_{} ::: *.jpg
962788:31.87

So 200 files were rotated and resized in 32s and conversion needed around 1gb of memory at peak.

By experimenting and looking for other examples,

i found that this imagemagick command operates per file and not in same time on all files:

 for pic in *.jpg; do convert -units PixelsPerInch  -rotate -90  -density 300 -quality 95  -resize 28% "$pic" "$pic";done

Note: if you dont want to replace original photo, the last "$pic" may be manipulated. eg. "$pic" "${pic//}_copy.jpg"

Related