Blog of Alexander Mamchenkov … mammoth cave …

Archive for February, 2012

Twitter Weekly Updates for 2012-02-26

02.26.2012 · Posted in Personal

Cutting Image Background with ImageMagick

02.21.2012 · Posted in General, Technology

Here is a small sequence of commands to cut the image of background (given that background is a solid color):

ORIG_IMAGE_NAME=green.jpg;
NEW_IMAGE_NAME=green-trans.png;
TMP_COLOR=`convert $ORIG_IMAGE_NAME -crop 1x1+0+0 txt:- | sed -n 's/.*\(#\S\+\).*/\1/p'`;
convert $ORIG_IMAGE_NAME -bordercolor $TMP_COLOR -border 1x1 -alpha set -channel RGBA -fuzz 30% -fill none -floodfill +0+0 $TMP_COLOR -shave 1x1 $NEW_IMAGE_NAME

Just change the first to vars. You can also adjust the fuzz percentage if needed.

Twitter Weekly Updates for 2012-02-19

02.19.2012 · Posted in Personal