Monday, April 23, 2012

Moving line masks





1 comment:

  1. Hi - just dropping by to let you know I did that scratchboard project we discussed last year. Here's some unix code for drawing a raster with a pen plotter... (or a vinyl cutter with an engraving tip)

    regards,

    G

    #!/bin/sh
    if [ "$1" == "" ]; then
    echo "syntax: scratch graphics-file.ext"
    exit 1
    fi
    if [ "$2" != "" ]; then
    shift
    echo "scratch: unexpected parameter $@"
    exit 2
    fi
    if [ ! -f "$1" ]; then
    echo "scratch: $1 is not a file"
    exit 3
    fi
    GTMP=/tmp/g$$
    mkdir $GTMP
    # any drawing converion, scaling etc must be done externally. This just takes the B/W image and does a crude fill on it, producing an SVG output.
    convert -threshold "50%" -depth 1 $1 -negate $GTMP/BEFORE.png # -negate is needed for scratching, omit for pencil or ink drawing
    pushd $GTMP > /dev/null 2>&1
    cp /dev/null out.svg
    while true
    do
    # dilate (the portable way that works with old versions of convert):
    convert -quiet -regard-warnings BEFORE.png +repage -define "convolve:scale=!" -convolve 1,1,1,1,1,1,1,1,1 -threshold 0 AFTER.png
    convert BEFORE.png AFTER.png -compose Difference -composite -negate DELTA.png
    autotrace --centerline --filter-iterations 0 --error-threshold 1 DELTA.png --output-format svg > DELTA.svg
    head -2 DELTA.svg > HEADER.svg; tail -1 DELTA.svg > FOOTER.svg; fgrep path DELTA.svg >> out.svg
    identify -verbose AFTER.png | fgrep "000000 black"
    if (( $? != 0 ))
    then
    popd > /dev/null 2>&1
    cat $GTMP/HEADER.svg $GTMP/out.svg $GTMP/FOOTER.svg > "$1.svg" # sed 's/stroke:#000000/stroke:#ffffff/'
    rm -rf $GTMP
    exit 0
    fi
    mv AFTER.png BEFORE.png
    done

    ReplyDelete