Loading...

STORIES

Image Processing Devilry II

Time for some more ImageMagick.

Here's how to add a black outline to multiple images with transparent backgrounds in a folder:

for x in ~/Pictures/MyProject/*.png
do
read width height < <(identify -format "%w %h" $x)
width=$((width + 2))
height=$((height + 2))
convert -page $width'x'$height+1+2 $x -layers coalesce $x
convert $x \( -clone 0 -alpha extract -threshold 0 \) \( -clone 1 -blur 2x.25 -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 $x
done

If you wanted to add a black outline of about 1 pixel to all PNG images in your MyProject Pictures folder, and adjust the image size by adding 2 pixels to the height and width, while not scaling the image, and keeping it centred and fixed to the bottom.

Before:

After:

Credit to Jesse Munguia for his Skeleton sprite pack.