Skip to content

Instantly share code, notes, and snippets.

@aozimkov
Created February 11, 2019 11:00
Show Gist options
  • Save aozimkov/8744a8c703196ee7a691c9b2c5e0e18d to your computer and use it in GitHub Desktop.
Save aozimkov/8744a8c703196ee7a691c9b2c5e0e18d to your computer and use it in GitHub Desktop.
square image bash
#!/bin/bash
for FILE in $(ls *.jpg)
do
W=`identify -verbose "$FILE" | grep -oe "Geometry:.*" | sed -e 's/.*: //' | sed -e 's/x.*//'`
H=`identify -verbose "$FILE" | grep -oe "Geometry:.*" | sed -e 's/.*x//' | sed -e 's/+.*//'`
if [ "$W" -gt "$H" ]
then
mogrify "$FILE" -extent "$W"x"$W" -gravity center -quality 100 jpeg:"$FILE"
fi
if [ "$H" -gt "$W" ]
then
mogrify "$FILE" -extent "$H"x"$H" -gravity center -quality 100 jpeg:"$FILE"
fi
done
echo 'done'
# if you need to scale image you can use mogrify
# There is example below
# mogrify -adaptive-resize 800 -quality 70 -path new *.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment