Created
October 13, 2016 22:02
-
-
Save zaydek-old/c7199789e2e042d6cc6984aa27f7b23d to your computer and use it in GitHub Desktop.
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
function int { | |
if [[ $1 = *.* ]]; then | |
i=${1%.*} | |
d=${1#*.}; if (( ${d:0:1} >= 5 )); then i=$[i+1]; fi | |
echo $i | |
else echo $1; fi | |
} | |
function asp { | |
w=$(file $1); h=$w; w=${w#*,}; w=${w%*x*} | |
h=${h#*x}; h=${h%%,*} | |
int $(echo $w $h | awk '{ print ($1/$2)*100 }') | |
} | |
function zpx { | |
z=1000 | |
if (( $1 > $2 )); then px=($(echo $z $(int $(echo $1 $2 $z | awk '{ print $3/($1/$2) }')) )) | |
else px=($(echo $(int $(echo $2 $1 $z | awk '{ print $3/($1/$2) }')) $z)); fi | |
sips -z ${px[1]} ${px[0]} $png -s dpiWidth 72 $png -s dpiHeight 72 $png -s format jpeg $png --out "$1 $2" | |
} | |
dir=~/Downloads; cd $dir; sips -s format png *.jpg --out $dir; rm *.jpg | |
for png in $(ls *.png); do | |
case $(asp $png) in 6[8-9] | 7[0-9] | 8[0-3]) zpx 12 16;; | |
9[0-9] | 10[0-9] | 110) zpx 1 1;; | |
1[2-3][0-9] | 14[0-7] ) zpx 16 12;; | |
13[5-9] | 1[4-5][0-9] | 16[0-5]) zpx 24 16;; | |
2[4-8][0-9] | 29[0-3] ) zpx 32 12;; | |
*) osascript -e "tell application \"Terminal\" to display dialog \"$png\"";; esac | |
done; rm *.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment