I've been needing to add labels to our products at Hobbs ElectroOptics and have been suffering through keeping multiple versions of each label up to date. In the spirit of spending twice as long to script it as it takes normally I've been investigating using Inkscape's command line tool to batch process these.
A master version of the label with text boxes is useful for editing but can be a headache if the font isn't installed on the target computer. Exporting to paths means that wherever this SVG goes it will look the same as the original design.
inkscape ${FILENAME_IN} --export-text-to-path -o ${FILENAME_OUT}
This is more ambitious than text to path. I'm laser engraving the labels in some objects and printing labels for others. This should:
- Remove the laser engraving sections by color (Outline in red, guide markings in Blue, engraving in Black).
- Set the background color
- Set the engraved color
inkscape ${FILENAME_IN} --export-background=#ff0f00 -o ${FILENAME_OUT}.png
This is less pretty, I'm using sed to change the XML file directly setting the colour you want to remove to the background colour.
sed s/#000000/#ffffff/ ${FILENAME_IN}.svg >> ${FILENAME_OUT}.svg
FILENAME_IN=in.svg
FILENAME_OUT=out
BLACK=#000000
BACKGROUND=${BLACK}
BLUE=#0000ff
RED=#ff0000
WHITE=#ffffff
sed s/${BLUE}/${BACKGROUND}/ ${FILENAME_IN} > ${FILENAME_OUT}.svg
sed s/${RED}/${BLACK}/ ${FILENAME_OUT}.svg > ${FILENAME_OUT}.svg
inkscape ${FILENAME_OUT}.svg --export-text-to-path -o ${FILENAME_OUT}.svg
inkscape ${FILENAME_OUT}.svg --export-background=${BACKGROUND} -o ${FILENAME_OUT}.png
FILENAME_IN=label.svg
FILENAME_OUT=$(basename ${FILENAME_IN})-export
BLACK=\#000000
BACKGROUND=${BLACK}
BLUE=\#0000ff
RED=\#ff0000
YELLOW=\#ff00ff
WHITE=\#ffffff
DPI=1024
# Use Black for engraving
# Red for cutting
.PHONY: all
all: ${FILENAME_OUT}.png ${FILENAME_OUT}-preview.svg ${FILENAME_OUT}-engrave.svg ${FILENAME_OUT}-engrave-all.svg ${FILENAME_OUT}-path.svg ${FILENAME_OUT}-outline.svg
clean:
rm ${FILENAME_OUT}*.png ${FILENAME_OUT}*.svg
${FILENAME_OUT}-path.svg: ${FILENAME_IN}
inkscape $< --export-text-to-path -o $@
#
${FILENAME_OUT}-outline.svg: ${FILENAME_OUT}-path.svg
cat $< | sed s/${BLUE}/${WHITE}/ | sed s/${BLACK}/${WHITE}/ > $@
# Remove red and blue leaving engraving only
${FILENAME_OUT}-engrave.svg: ${FILENAME_OUT}-path.svg
cat $< | sed s/${BLUE}/${WHITE}/ | sed s/${RED}/${WHITE}/ > $@
# Turn all guides and cutting into black
${FILENAME_OUT}-engrave-all.svg: ${FILENAME_OUT}-path.svg
cat $< | sed s/${BLUE}/${BLACK}/ | sed s/${RED}/${BLACK}/ > $@
${FILENAME_OUT}-preview.svg: ${FILENAME_OUT}-path.svg
cat $< | sed s/${BLACK}/${WHITE}/ | sed s/${BLUE}/${BACKGROUND}/ | sed s/${RED}/${BACKGROUND}/ > $@
${FILENAME_OUT}.png: ${FILENAME_OUT}-preview.svg
inkscape $< --export-dpi=${DPI} --export-background=${BACKGROUND} -o $@