Ommadawn
Ommadawn

Reputation: 2730

Convert image bank using parallel

I've a bank of images and I used to use ImageMagick Convert to resize them, but I would like to take advantage of the power of multi-core by using the parallel command.

The statement I use to perform the single core conversion is as follows:

find . -type f -iname "*.jpg" -exec convert {} -quality 90 -format jpg -resize 240x160 ../small/{} \;

It works prefectly, but the problem is that, by default, convert only uses a single core to perform the process. So, how can I use parallel to use any number of cores I want to perform the same job?

Thanks!

Upvotes: 2

Views: 329

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207355

It should be something like this:

find . -type f -iname "*.jpg" -print0 |
    parallel -0 convert {} -quality 90 -resize 240x160 ../small/{}

Test it with find ... | parallel --dry-run ...

Note that I am using find ... -print0 and parallel -0 to match it so that filenames are null-terminated and spaces in filenames don't cause issues.


By default this will use all available cores. If you want to use just 2 cores, try:

parallel -j 2 ...

If you want to use all but one of your cores, try:

parallel -j -1 ...

If you want to use half your cores, try:

parallel -j 50% ...

Upvotes: 3

Related Questions