Skip to content

Instantly share code, notes, and snippets.

@Glutnix
Created September 29, 2014 05:49
Show Gist options
  • Save Glutnix/f83e89ff3ec590c65d36 to your computer and use it in GitHub Desktop.
Save Glutnix/f83e89ff3ec590c65d36 to your computer and use it in GitHub Desktop.
ImageMagick - scale up a folder of 14x14 alpha png images, add a black border, and save it.
#!/bin/bash
# IMAGEMAGICK
# scale image up using nearest neighbour
# extend canvas larger
# layer 1: clone 0, extract the alpha layer, and contrast it to black and white only, no grey
# layer 2: clone 1, blur clone 0 by 3px, then contrast it
# layer 3: clone 2: fill black with opaque white
# take layer 3, 0, 1, ignoring alpha, composite them over each other.
# delete layers 0,1,3, swap the last two layers, and, ignoring alpha, composite all the layers together copying the alpha layer
for file in `find . -name \*.png -print`; do
convert $file \
-scale '300%' \
-interpolate integer \
-background none \
-gravity center \
-extent 48x48 \
\( -clone 0 -alpha extract -threshold 0 \) \
\( -clone 1 -blur 3x65535 -threshold 0 \) \
\( -clone 2 -fill black -opaque white \) \
\( -clone 3 -clone 0 -clone 1 -alpha off -compose over -composite \) \
-delete 0,1,3 +swap -alpha off -compose copy_opacity -composite \
bordered/$file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment