Researching generating playing cards from an SVG template using Inkscape
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
- Tutorial on how to use it
- Mentioned in this blog
- 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:
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 inkscape_merge
:
This does seem to work! Assuming I start with a correctly formatted table_cards.csv
and template.svg
(from following the above blog post):
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:
- https://alpha.inkscape.org/vectors/www.inkscapeforum.com/viewtopic4dfb.html?t=999
- https://inkscape.org/forums/questions/text-inside-a-shape-half-text-box-half-following-a-path/
- https://stackoverflow.com/questions/2938779/svg-scaling-text-to-fit-container
- https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
- https://github.com/borgand/inkscape_merge/blob/master/lib/inkscape_merge/processor.rb
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.