I’m working on developing a board game, and would like to make some playing cards for it. My thinking is that it should be possible to have one (or a few) SVG templates (made in Inkscape), which are then populated with data from a CSV (or otherwise), somewhat akin to mail-merge. This would then make it easy to iterate on the design by updating the CSV file and then automatically generating a new set of playing cards, which could be printed off.
Card generation §
Here’s what I’ve found from various searches relating to this problem:
- How to create an Inkscape extension
- Example Inkscape extension
- Standalone Python SVG mail merge tool
- Standalong Ruby SVG mail merge tool
- Blog post with workflow
- Inspired by Bash mail merge extension (see below)
- Bash Inkscape mail merge extension
- Unrelated - the current most popular Inkscape extension
Fortunately it appears I’m not the first person to want to do something along these lines, so it seems very plausible. Unfortunately the tooling all seems rather outdated and/or sparsely documented.
To start off, I tried to use the Bash Inkscape mail merge extension.
It adds a new option into the Inkscape GUI which lets you do mail merge.
Unfortunately, when I tried to run it, it failed with the following error:
/usr/share/inkscape/extensions/generator.sh: eval: line 79: syntax error near unexpected token `(' /usr/share/inkscape/extensions/generator.sh: eval: line 79: `col_name=Action_(then_discard)'
Next I looked into the Ruby extension instead, following through the blog post.
First of all, install Ruby if it’s not installed already, then install
sudo gem install inkscape_merge
This does seem to work! Assuming I start with a correctly formatted
template.svg (from following the above blog post):
mkdir batch inkscape_merge -f template.svg -d table_cards.csv -o batch/card_%d.png --format png
This then populates the
batch directory with all the generated PNG files.
One problem is that if the text is larger than the textbox, it just spills out. It would be nice if the font size would automatically adjust to fill the pre-defined textbox area.
Here are some initial notes on looking into this:
Unfortunately it doesn’t seem as easy as I had hoped it might.
Fortunately it turns out there is a much simpler solution, though it requires a little more manual work:
Include a placeholder textbox in the SVG file for each font size you wish to support. Then have a column in the CSV file for each of these font sizes. Leave all these columns empty except for the font size which is most suitable.
This requires a little bit of trial-and-error, but seems good enough for my circumstances.