Skip to content

Instantly share code, notes, and snippets.

@cab404 cab404/9patch-resize.sh
Last active Mar 29, 2018

Embed
What would you like to do?
Resizer for 9patch images based on im utils
#!/bin/bash
# resizer for android 9patch icons
# getting center part
convert -shave 1 $1 core.png
# getting sides
convert -gravity West -crop 1x+0+0 $1 l.png
convert -gravity East -crop 1x+0+0 $1 r.png
convert -gravity South -crop x1+0+0 $1 b.png
convert -gravity North -crop x1+0+0 $1 t.png
convert core.png -resize $2 -bordercolor transparent -border 1 core.png
w=`identify -format '%w' core.png`
h=`identify -format '%h' core.png`
composite -gravity East \( r.png -filter Point -resize 1x${h}! \) core.png core.png
composite -gravity West \( l.png -filter Point -resize 1x${h}! \) core.png core.png
composite -gravity South \( b.png -filter Point -resize ${w}x1! \) core.png core.png
composite -gravity North \( t.png -filter Point -resize ${w}x1! \) core.png out.png
rm l.png r.png b.png t.png core.png
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.