Skip to content

Instantly share code, notes, and snippets.

@JayNewstrom JayNewstrom/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
Resize image assests, starting with an image in your res/drawable-xxxhdpi folder.

Origionally based off: https://gist.github.com/ignasi/8420671

Setup

chmod +x resizer_xxxhdpi.sh

copy resizer_xxxhdpi.sh to res/drawable-xxxhdpi/resizer_xxxhdpi.sh

Usage

Start with the image you want to resize, we'll call it resize_me.png (remember, android resources can't have caps, or dashes)

copy resize_me.png to res/drawable-xxxhdpi/resize_me.png

./resizer_xxxhdpi.sh resize_me.png

#!/bin/bash
# fake argv and argc in bash
argc=$#; argv[0]=$0 # argv[0] is a prog name
for foo in $( seq $argc )
do
eval "argv[${foo}]=\$${foo}"
filename=${argv[$foo]}
width=$(sips -g pixelWidth $filename | tr -d '\n' | awk '{ print $NF }')
sips --resampleWidth $(($width/4)) "${filename}" --out "../drawable/${filename}"
sips --resampleWidth $(($width/8*3)) "${filename}" --out "../drawable-hdpi/${filename}"
sips --resampleWidth $(($width/2)) "${filename}" --out "../drawable-xhdpi/${filename}"
sips --resampleWidth $(($width/4*3)) "${filename}" --out "../drawable-xxhdpi/${filename}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.