Search code examples
linuximagemagick-convertgnu-parallel

How to resize multiple png files with parallel command and keep a part of name from the source file?


I have 100 png files in the same Linux folder and I want to create thumbnails from them. For example the source files are:

page_1.png
page_2.png
...
page_100.png

I want to create 100 thumbnails in the same folder with the names like:

thumbnail_1.png
thumbnail_2.png
...
thumbnail_100.png

I tried the next command:

ls -1 page_*.png | parallel -j 3 convert {} -resize 120 thumbnail_{.}.png

but the created files are named as

thumbnail_page_1.png 
thumbnail_page_2.png
...
thumbnail_page_100.png

Solution

  • You can use a perl expression to get the effect :

    parallel -j 3 convert {} -resize 120 {= s/page/thumbnail/ =} ::: page_*.png