Created
July 8, 2016 01:36
-
-
Save btray77/4c9adae09bca02a675b84f7d2a99cfb6 to your computer and use it in GitHub Desktop.
Resize images in a folder to a minimum size, keep aspect ratio.
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 | |
#Edit webroot to meet your needs | |
IFS=$'\n' | |
set -e | |
minimumWidth=1000 | |
minimumHeight=1000 | |
FILES=$(find /webroot/media/catalog/product/ \( -name cache -prune \) -o -name '*' -type f -exec file {} \; | awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}') | |
AMOUNT=`echo $FILES | wc -w` | |
COUNTER=0 | |
if [ ! -z "$FILES" ]; | |
then | |
for F in $FILES | |
do | |
imageWidth="$(identify -format "%w" "$F")" | |
imageHeight="$(identify -format "%h" "$F")" | |
if [ "$imageWidth" -ge "$minimumWidth" ] || [ "$imageHeight" -ge "$minimumHeight" ]; then | |
echo "Not Changed. " ''"$imageWidth"x"$imageHeight"'' "$F" | |
else | |
#echo "Initial Size" | |
#ls -lah "$F" | awk -F " " {'print $5'} | |
mogrify -resize ''"$minimumWidth"x"$minimumHeight<"'' "$F" | |
#echo "Resized Size" | |
#ls -lah "$F" | awk -F " " {'print $5'} | |
let COUNTER=COUNTER+1 | |
NewimageWidth="$(identify -format "%w" "$F")" | |
NewimageHeight="$(identify -format "%h" "$F")" | |
echo "Mogrifyed. $NewimageWidth"x"$NewimageHeight" | |
fi | |
done | |
fi | |
echo "Done! $COUNTER of $AMOUNT files found and changed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment