Generate playing cards deck from python config and SVG templates.
Project description
deckbro
deckbro is a python library to generate cards deck using SVG templates.
/!\ This software has not been toroughly tested. Please carefully check its outputs before sending them for expensive operations as quality printing.
Key features :
- Use SVG files as templates
- Declarative semantics, for ease of use
- Parametric and extendable model through Python
- Generates SVG for cards, as well as pdf sheets grouping cards ready for double-sided printing
- Any card and sheet format
Caveats :
- May not handle advanced SVG constructs. Should be improved over time.
- Sheet layout not automated. Should be improved over time.
- Still lacking some flexibility in design possibilities. Should be improved over time.
- While it should be possible to make it work, at least partially, on any system, it is only designed and tested for Linux. No plan to improve it by myself unless a lot of people request it. MR are welcome, feel free to message me before working to confirm your design is fine.
Install
You can either install sources or download from PyPI.
pip install deckbro
In addition, depending on functionnalities you use, you will need to have :
- Inkscape
- pdfunite
- Chromium
- pdftocairo (usually provided along Poppler, itself provided alongside Inkscape)
Quick example
First, let's define a very simple svg template, named template.svg :
<svg xmlns="http://www.w3.org/2000/svg" width="96" height="48" viewBox="0 0 96 48" fill="none">
<rect width="48" height="48" rx="0" fill="#efefef"/>
<rect width="48" height="48" x="48" fill="#fefefe"/>
<text x="48" y="24" font-family="monospace" fill="#000000" text-anchor="middle" dominant-baseline="central">TITLE</text>
</svg>
Then, we can define our deck using deckbro, in a deck.py file, not using any factorization mechanism to keep things simple:
from deckbro.deck import Card, Deck
from deckbro.svg import SVGFile, StrSub
from deckbro.render import render
# A face is simply composition of SVG nodes.
# Through using a function, we can build a parametric model
def face(left_color : str, right_color: str, title : str) -> StrSub:
return StrSub( #StrSub allows to perform string substitution on a SVG given a parameter
SVGFile("template.svg"), #Take svg from a template.svg file
{
"#efefef" : left_color, #efefef will be replaced by left_color's value everywhere in the svg loaded from template
"#fefefe" : right_color,
"TITLE" : title
}
)
# A card has an identifier (used for file generation)
# and two faces
# as well as an optional count if multiple copies are needed in the deck.
Card("pink_green",
face("#e362a0", "#62e378", "Pink Green"),
face("#b8b8b8", "#bdbdbd", "PG Back")
)
#Cards are automatically added to the deck, not need to do it by hand.
Card("blue_red",
face("#6293e3", "#e37562", "Blue Red"),
face("#b8b8b8", "#bdbdbd", "BR Back")
)
#Export deck to files
render()
Run the script. It will (if everything goes right) create a build directory containing a PDF document grouping all cards front and backs, ready for double-sided printing, called gen_sheets.pdf. And also :
- SVG file for each card
- SVG file per-sheet
- PDF file per-sheet
See content of examples/quick/expected for details.
Quick doc
A card face is a tree of SVGNode
A SVGNode is an operation on an SVG tree, usually applying to the values from its children nodes.
Currently provided nodes are :
SVGFileloading SVG from a fileStrSubreplacing substrings in a SVG Element stringGroupassembling multiple SVG Elements into oneTransformapplying a transformation on an ElementRFTextreplacing a rectangle by a text, and making the text fit the rectangle's area by shrinking the font if necessary.
Please see code for documentation and other examples for more info.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deckbro-0.0.1.tar.gz.
File metadata
- Download URL: deckbro-0.0.1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64622668eafa72a3c51f467edf77677c5b4239b318d477d5df2dbffd11db9fab
|
|
| MD5 |
e899c77efea73601f9dbb0902e72da33
|
|
| BLAKE2b-256 |
0655b70e1c09e6199ad16c96608c05f19c87c323747ea04291e9c3612ab52aab
|
File details
Details for the file deckbro-0.0.1-py3-none-any.whl.
File metadata
- Download URL: deckbro-0.0.1-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1efedd2d47d8bb658e2edd3833c634247a59cbfa10f432ffbbf70b2cc90396fd
|
|
| MD5 |
3ab94b31cfd22aff594033c12cc7a1ef
|
|
| BLAKE2b-256 |
66a35a722ebe519ebea34d0688c51a711f557dc995eef0d89f71a2b34aa9a032
|