Wednesday, May 24, 2017

Bash to resize images using imageMagick

Taken the idea from unix.stackexchange.com
#!/bin/bash

files=*
W=800
H=600
SIZE_TEST="%[fx:(h>$H && w>$W)]"'\n'

for f in $files
do
    if [ $(identify -format "$SIZE_TEST" "$f") = 1 ]; then
      echo "Resize: $f"
      mogrify -resize ''"$W"x"$H"'' "$f"
    else
      echo "Do not resize: $f"
    fi
done

No comments:

Post a Comment