A Python-based tool for generating high-quality trading cards from CSV data using HTML templates and browser rendering.
Generate print-ready card assets from a csv with css and jinja.
- Python 3.6+
- A modern web browser (Firefox, Chrome, or Edge)
- Clone this repository
- Install Python dependencies:
pip install -r requirements.txt
- Prepare your card data in a CSV file with columns: id, name, type, cost, effect, quote, source, image_path
- Place card images in your preferred directory structure
- Create your HTML templates in the templates directory
- Run the generator:
python card_generator.py games/your_game
To create your own card set, follow this structure:
games/
your_game/
templates/ # Directory for HTML templates
card_template.html # Main card template
back_template.html # Card back template (optional)
cards.csv # Card data
styles/ # Directory for CSS files (optional)
base.css # Base styles
custom.css # Additional styles
styles.css # Default CSS file (optional if using styles directory)
img/ # Image directory (can be organized as needed)
fonts/ # Custom fonts (optional)
-
cards.csv: Contains card data with the following columns:- id: Unique identifier for the card
- name: Card name
- type: Card type
- cost: Card cost
- effect: Card effect/description
- quote: Flavor text (optional)
- source: Quote source (optional)
- image_path: Path to the card's image file, relative to the game directory
- style_path: Path to the card's base CSS file (optional)
- supplementary_style: Path to additional CSS file for this card (optional)
-
templates/card_template.html: HTML template using Jinja2 syntax -
CSS file(s): At least one CSS file is required. The system will look for CSS files in the following order:
- Per-card style files specified in the CSV (style_path and supplementary_style)
- Default base.css in the game directory
- Empty cells in the CSV are handled gracefully
- Optional columns (quote, source, style_path, supplementary_style) can be left blank
- Numeric values (cost) are automatically converted to integers
- Each card is assigned a serial number based on its position in the CSV
python card_generator.py [GAME_DIR] [OPTIONS]
Arguments:
GAME_DIR Path to the game directory containing cards.csv and templates/card_template.html
Options:
--browser TEXT Browser to use for rendering: firefox|chrome|edge (default: firefox)
Basic usage:
python card_generator.py games/my_gameUsing Chrome for rendering:
python card_generator.py games/my_game --browser chrome