source=$1
in=$1.tmp.png
id=$(echo "$1" | cut -d \. -f1)
out=$2
if [ -z "$2" ]; then
echo Parametros insuficientes
exit 1
fi
#
# Add white frame
#
convert $source -bordercolor white -border 1x1 $in
difference="$id".tmp.png
removed_black="$id".tmp.rmblack.png
#removed_black_check="$id".tmp.rmblack.ck.png
matte="$id".tmp.matte.png
matte_negated="$id".tmp.matte.negated.png
# start real
convert $in \( +clone -fx 'p{0,0}' \) -compose Difference -composite -modulate 100,0 +matte $difference
# remove the black, replace with transparency
convert $difference -bordercolor white -border 1x1 -matte -fill none -fuzz 7% -draw 'matte 1,1 floodfill' -shave 1x1 $removed_black
#composite -compose Dst_Over -tile pattern:checkerboard $removed_black $removed_black_check
# create the matte
convert $removed_black -channel matte -separate +matte $matte
# negate the colors
convert $matte -negate -blur 0x1 $matte_negated
# you are going for: white interior, black exterior
composite -compose CopyOpacity $matte_negated $in $out
#composite -compose Dst_Over -tile pattern:checkerboard $out $id.new.check.png
rm $id.tmp*
Grandísimo