metalx1000

Imagemagick crop images to square

Sep 1st, 2020
1,415
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #crops all images to a square
  3. #set output size
  4. size="300"
  5.  
  6. for i in ../imgs/*;
  7. do
  8.   #get longest side
  9.   s="$(identify -format "%[fx:min(w,h)]x%[fx:min(w,h)]+0+0" $i)"
  10.  convert $i -gravity center -crop $s -resize $size "$(basename $i)"
  11. done
RAW Paste Data