Created
February 11, 2019 11:00
-
-
Save aozimkov/8744a8c703196ee7a691c9b2c5e0e18d to your computer and use it in GitHub Desktop.
square image bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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