Skip to content

Instantly share code, notes, and snippets.

@rfc1459
Created July 29, 2012 16:14
Show Gist options
  • Save rfc1459/3199995 to your computer and use it in GitHub Desktop.
Save rfc1459/3199995 to your computer and use it in GitHub Desktop.
Programmatically resize banners for MOCA app
#!/bin/bash
IMAGES=$@
resize() {
local DENSITY=$1
shift
local SIZE=$1
shift
local UNSHARP=$1
for i in ${IMAGES}; do
IMG="`basename "$i"`"
echo "[${DENSITY}] Resizing $i"
if [ ${UNSHARP} -eq 1 ]; then
convert "$i" -filter Lanczos -resize ${SIZE}\> -unsharp 0x2+0.2+0.314 -type Palette -format png8 -strip "${DENSITY}/${IMG}"
else
convert "$i" -filter Lanczos -resize ${SIZE}\> -type Palette -format png8 -strip "${DENSITY}/${IMG}"
fi
done
}
DENSITIES=( xhdpi hdpi mdpi ldpi )
SIZES=( 600x100 450x75 300x50 225x38 )
UNSHARP=( 0 0 1 1 )
mkdir -p ${DENSITIES[@]}
for i in `seq 0 $((${#DENSITIES[@]} - 1))`; do
resize ${DENSITIES[$i]} ${SIZES[$i]} ${UNSHARP[$i]}
done
echo -n "Performing final optimization pass..."
for density in ${DENSITIES[@]}; do
optipng -o7 ${density}/*.png 2>&1 >/dev/null
done
echo " done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment