Skip to content

Instantly share code, notes, and snippets.

@niqueco
Created December 12, 2014 02:43
Show Gist options
  • Save niqueco/af29ad205fbdf9d58d13 to your computer and use it in GitHub Desktop.
Save niqueco/af29ad205fbdf9d58d13 to your computer and use it in GitHub Desktop.
Utility to "tint" an Android nine-patch file without breaking it using ImageMagick
#! /bin/bash
set -e
if [ $# -lt 2 ]; then
echo Usage: >&2
echo " $0 color image..." >&2
exit 1
fi
color="$1"
shift
for fn in "$@"; do
g=$(echo $( file "$fn" | sed -nre 's/^.* ([0-9]+) x ([0-9]+),.*$/\1 - 2\n\2 - 2/p' | bc ) | tr " " x)
tmp="$(mktemp)"
convert "$fn" -gravity center -region "$g" -fill "$color" -fuzz 90% -opaque white "$tmp"
mv "$tmp" "$fn"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment