Advertisement
PsHegger

Android image resizer script

Feb 22nd, 2016
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. f=$(pwd)
  4. original_width=$(sips -g pixelWidth $f/drawable-xxxhdpi/$1 | grep "pixelWidth" | tr " " "," | cut -d "," -f4)
  5. txw=$((original_width/4))
  6.  
  7. for i in {1..4}
  8. do
  9.   case $i in
  10.   1*)
  11.     dir="drawable-mdpi"
  12.     scale=1
  13.     ;;
  14.   2*)
  15.     dir="drawable-hdpi"
  16.     scale=1.5
  17.     ;;
  18.   3*)
  19.     dir="drawable-xhdpi"
  20.     scale=2
  21.     ;;
  22.   4*)
  23.     dir="drawable-xxhdpi"
  24.     scale=3
  25.     ;;
  26.   esac
  27.  
  28.   size=$(bc -l <<< "scale=0; $txw*$scale")
  29.   sips --resampleWidth $size "$f/drawable-xxxhdpi/$1" --out "$f/$dir/$1"
  30. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement