Bash + ImageMagick generate photo thumbnails

Date: 2020-07-07

https://imagemagick.org/script/download.php

https://imagemagick.org/download/binaries/magick

#!/bin/bash
files=`ls ./Camera/*.jpg`
for file in $files; do
    #dir=`dirname $file`
    name=`basename -s .jpg $file`
    new="./$name.jpg"
    (set -x ; ./magick convert $file -auto-orient -resize 25% -quality 90 $new)
    #break; # break on first iteration
done;

With some parallelism:

#!/bin/bash
found=`find ./Camera -iname '*.jpg'`
files=($(echo $found | tr ',' "\n"))
n=3 # number of parallel tasks
cnt=${#files[@]}
for ((i = 0; i < $cnt; ++i)); do
    #dir=`dirname $file`    
    file=${files[$i]}
    name=`basename $file`
    new="./${name%%.*}.jpg"
    while (( `jobs | wc -l` >= $n )); do
        wait -n
    done
    echo "$(( $i + 1 )) / $cnt"
    (set -x ; ./magick convert $file -resize 1200x1200 -quality 90% -auto-orient $new) &
    #break; # break on first iteration
done
wait
#!/bin/bash
found=`find ./ -iname '*.pdf'`
readarray -t files <<<"$found"
cnt=${#files[@]}
convert="./magick convert"

for ((i = 0; i < $cnt; ++i)); do
    #dir=`dirname $file`    
    file=${files[$i]}
    name=`basename "$file"`
    new="./${name%%.*}.jpg"
    echo "$(( $i + 1 )) / $cnt"
    echo "$convert \"$file\" -density 300x300 -quality 90 \"$new\""
#    (set -x ; ./magick convert \"$file\" -density 300x300 -quality 90 \"$new\")
    #break; # break on first iteration
done
38300cookie-checkBash + ImageMagick generate photo thumbnails