Skip to content

Instantly share code, notes, and snippets.

@josecostamartins
Created February 6, 2015 17:22
Show Gist options
  • Save josecostamartins/ced5402e161f0eea90c8 to your computer and use it in GitHub Desktop.
Save josecostamartins/ced5402e161f0eea90c8 to your computer and use it in GitHub Desktop.
for FILE in *.jpg; do
echo "Processing file: $FILE"
WIDTH=`identify $FILE | awk '{split($3,a,"x"); print a[1]}'`
HEIGHT=`identify $FILE | awk '{split($3,a,"x"); print a[2]}'`
if [ "$WIDTH" -gt 1024 -o "$HEIGHT" -gt 1024 ]; then
if [ "$WIDTH" -gt "$HEIGHT" ]; then
RATIO=$(echo 1024/$WIDTH | bc -l)
else
RATIO=$(echo 1024/$HEIGHT | bc -l)
fi
WIDTH_NEW=$(echo "$WIDTH * $RATIO" | bc -l | python -c "print int(round(float(raw_input())))")
HEIGHT_NEW=$(echo "$HEIGHT * $RATIO" | bc -l | python -c "print int(round(float(raw_input())))")
#echo "SIZE: $SIZE"
#echo "FILE: $FILE"
convert $FILE -resize "$WIDTH_NEW"x"$HEIGHT_NEW" "$FILE"
#echo "RATIO: $RATIO"
#echo "WIDTH: $WIDTH"
#echo "HEIGHT: $HEIGHT"
#wd="$WIDTH * $RATIO" | bc -l
#echo "$w"
#php -r 'echo round('$wd');'
#echo $(round2 "$wd" 0)
#echo `identify $file`
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment