Skip to main content

Generate playing cards deck from python config and SVG templates.

Project description

deckbro

deckbro is a python library to generate cards deck using HTML templates.

/!\ This software has not been toroughly tested. Please carefully check its outputs before sending them for expensive operations as quality printing.

Key features :

  • Uses HTML 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
  • Tools to auto-fit text in element.

Caveats :

  • You have to do the layout work. But using HTML/CSS/JS so not too hard.
  • Not able to easily compose HTML for now. Should not be too much of a hindrance and should be improved overtime.
  • Sheet layout not automated. 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 and Forks are welcome. Be sure to open an issue/message me before starting to work on a MR, so I can confirm this will be accepted or not beforehand.

Install

You can either install sources or download from PyPI.

pip install deckbro

In addition you will need to have :

  • Inkscape
  • pdfunite
  • Chromium
  • pdftocairo (usually provided along Poppler, itself provided alongside Inkscape)

installed on the computer and invokable from cli.

Quick overview

Here is a summary of the example contained in examples/base directory.

We define a template for a card face :

<!DOCTYPE html>

<html>
<head>
    <link rel="stylesheet" href="template.css" /> <!--provided by deckbro -->
    <script src="template.js"></script> <!-- provided by deckbro -->
</head>
<style>
    @page {
        margin: 0;
        padding: 0;
        size: 600px 800px;
    }
</style>
<body id="body" style="padding: 0px; margin: 0px; width: 600px; height:800px; color:#1e1e1e; font-family: sans-serif;">
    <div style="padding : 20px; margin: 0px; background-color : #1e1e1e; height: 100%; border-radius: 20px; box-sizing: border-box;">
        <div class="fit-text" style="font-size: 60px; font-weight: bold; text-align: center; vertical-align: middle; height: 10%; background-color: white; border-radius: 20px;">
            TITLE  <!-- TITLE is a placeholder -->
        </div>
        <div style="height: 50%;">
            <div style="display: flex; align-items: center; justify-content: center; height: 100%;">
                <img src="magician.svg" height="300px" width="300px" style="margin: auto;"> <!-- magician.svg is a placeholder -->
            </div>
        </div>
        <div class="fit-text" style="font-size: 30px; border-radius: 20px; background-color: white; height: 40%; box-sizing: border-box; padding: 20px;">
            DESCRIPTION <!-- DESCRIPTION is a placeholder -->
        </div>
    </div>
</body>

</html>

That we can use in a python file to declare a deck :

from deckbro.deck import Card, Deck
from deckbro.html import HTMLFile, StrSub
from deckbro.render import render

#dimensions of cards
Deck.instance().config.cards.width = 60 
Deck.instance().config.cards.height = 80


# we can use the power or Python to build our faces. A face is a composition of HTMLnodes
#here is front side
def front(title : str, image : str, description : str) -> StrSub:

   
    return StrSub(  # replace strings in HTML
        HTMLFile("deck/front.html"), #Take html from front.html
        {
            "TITLE" : title, #TITLE becomes title
            "DESCRIPTION" : description, #etc...
            "magician.svg" : image, # we define another image
        }
    )

# here is back side.
def back() -> HTMLFile :
    return HTMLFile("deck/back.html")

#Then we register a card with a front and a back.
Card("magician",
    front("Magician", "magician.svg", "A magical being able to magically vaporize enemies with their FIREBALLS."),
    back()
)

#and more cards.
Card("enchanter",
    front("Enchanter", "enchanter.svg", "A complex being, capable of vowing durable enchantments on themselves, others, places, and items. Some even say that they are able to enchant spells. Enchanting magic is a very complicated topic, which requires years of training for one to master. The strongest enchanters can even bend reality. See, one of them automatically reduced the font size of this text so it fits in the card !"),
    back()
) 

# ...

#finally, we export deck. It renders SVG file for each card, as well as A4 pdf sheets for double sided printing.
render()

Run the script and Voilà !

Here are some of the cards fronts generated :

magician enchanter

You can also see the generated printing sheets

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deckbro-0.0.2.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deckbro-0.0.2-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file deckbro-0.0.2.tar.gz.

File metadata

  • Download URL: deckbro-0.0.2.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for deckbro-0.0.2.tar.gz
Algorithm Hash digest
SHA256 32ccfc61cc22de9252463802672538fa0d231fea3add4128959b5cdf04e86100
MD5 75ded33ece9da0ef76f242dba47f5f75
BLAKE2b-256 babf0ab3b3e47198a9f5e04e18b6e90f3d361084386073e0fb9bffdc4fc7062f

See more details on using hashes here.

File details

Details for the file deckbro-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: deckbro-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for deckbro-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3ec4874a7563c95c798ca7b2a97dd3e1d549b1c42ef90bb44a8a42dbcefeca56
MD5 32e9eac175493a44bff28c8a85517b8b
BLAKE2b-256 5947c1cd35cf32299a2abfc65bad590f54adef6c873be665bcec1688b26a9207

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page