0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00
penpot/experiments/scripts/trace.sh
2020-06-18 20:08:46 +02:00

58 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env sh
set -ex
combine(){
pnmpaste -or tmp/cmask-invert-${1}.pbm 0 0 tmp/cmask-invert-${2}.pbm > tmp/combine-tmp.pbm
mv tmp/combine-tmp.pbm tmp/cmask-invert-${2}.pbm
}
invert() {
pnminvert tmp/cmask-${1}.pbm > tmp/cmask-invert-${1}.pbm
}
invert2() {
pnminvert tmp/cmask-invert-${1}.pbm > tmp/cmask-${1}.pbm
}
mask() {
ppmcolormask "#${1}" $INPUT_FILE > tmp/cmask-${1}.pbm
}
trace() {
#potrace --svg --opttolerance 5 --alphamax 1.334 tmp/cmask000.pbm
potrace --svg --color "#${1}" tmp/cmask-${1}.pbm
}
svg_prepend(){
xsltproc --stringparam prepend tmp/cmask-${1}.svg combine.xslt trace-output.svg > tmp/combine-tmp.svg
mv tmp/combine-tmp.svg trace-output.svg
}
#COLORS=ffffff c5eeff ddd9d4 fdb696 c9463b 736026 af1a1a 3c3b39 6e0c00
COLORS="6a0909 302621 22323f af1a1a 43551e 60492d 3f515f 8f3131 7a543b 677a88 e17070 e99282 b3adad f6b18f ffd86f d5dfe1 f2f2f2 ffffff"
INPUT_FILE=$1
mask 000000
invert 000000
previous=
for color in $COLORS
do
mask ${color}
trace ${color}
invert ${color}
combine ${color} 000000
if [ -n "$previous" ]
then
svg_prepend ${color}
else
cp tmp/cmask-${color}.svg trace-output.svg
fi
previous=${color}
done
invert2 000000
trace 000000
svg_prepend 000000