Skip to main content

About

fentoboardimage takes a Fen string representing a Chess position, and renders a PIL image of the resulting position.

Examples

Examples can be found under the examples folder in this repository.

You can customize:

  • the size and color of the board
  • piece sprites
  • black or white perspective
  • Board highlighting for last move
  • Arrows

Installation

Install the package using pip

$ pip install fentoboardimage

Then import the functions and use them as follows:

from fentoboardimage import fen_to_image, load_pieces_folder

board = fen_to_image(
    fen="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
    square_length=100,
    piece_set=load_pieces_folder("./pieces"),
    dark_color="#D18B47",
    light_color="#FFCE9E"
)
board.save("board.png")

Asset Setup

All asset paths are relative to your current working directory (where you run your script).

Piece Set Structure

your_project/
├── main.py
└── pieces/           # Path: "pieces" or "./pieces"
    ├── white/
    │   ├── King.png
    │   ├── Queen.png
    │   ├── Rook.png
    │   ├── Bishop.png
    │   ├── Knight.png
    │   └── Pawn.png
    └── black/
        ├── King.png
        ├── Queen.png
        ├── Rook.png
        ├── Bishop.png
        ├── Knight.png
        └── Pawn.png

Arrow Set Structure (Optional)

arrows/
├── Knight.png    # L-shaped arrow (3:2 ratio, points bottom-right → top-left)
└── Up.png        # Straight arrow (1:3 ratio, points upward, 3 sections: head/body/tail)

See the documentation for detailed arrow sprite specifications.

Making Paths Portable

For scripts that may run from different directories, use __file__ to resolve paths relative to your script:

import os

script_dir = os.path.dirname(os.path.abspath(__file__))
pieces_path = os.path.join(script_dir, "pieces")

piece_set = load_pieces_folder(pieces_path)

Usage

fen_to_image Parameters

Parameter Type Description
fen str FEN string representing the position
square_length int Length of one square in pixels (board = 8 × square_length)
piece_set Callable Piece set loaded via load_pieces_folder()
dark_color str Hex color for dark squares (e.g., "#D18B47")
light_color str Hex color for light squares (e.g., "#FFCE9E")
flipped bool Render from black's perspective (default: False)
arrow_set Callable Arrow set loaded via load_arrows_folder() (optional)
arrows list List of [start, end] squares, e.g., [["e2", "e4"]] (optional)
last_move dict Highlight last move with before, after, darkColor, lightColor keys (optional)
coordinates dict Display coordinates with font, size, dark_color, light_color, position_fn keys (optional)

Loading Functions

load_pieces_folder(path, cache=True)

Loads piece images from a folder. Returns a callable for use with piece_set.

load_arrows_folder(path, cache=True)

Loads arrow sprites from a folder. Returns a callable for use with arrow_set.

load_font_file(path)

Loads a TrueType font for coordinates. Returns a callable that accepts font size.

Development

This project uses UV for dependency management.

Setup

Install UV (if not already installed):

curl -LsSf https://astral.sh/uv/install.sh | sh

Clone the repository and install dependencies:

git clone https://github.com/reedkrawiec/fenToBoardImage.git
cd fenToBoardImage
uv sync

Running Tests

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run specific test file
uv run pytest test/test_unit.py

# Run specific test class
uv run pytest test/test_unit.py::TestFenParser

Code Formatting

This project uses Black for code formatting:

# Format all Python files
uv run black .

# Check formatting without making changes
uv run black --check .

Documentation

Build the documentation locally:

# Build static site
uv run mkdocs build

# Serve locally with live reload
uv run mkdocs serve

The documentation will be available at http://127.0.0.1:8000/.

Dependencies

Metadata

Release files for fentoboardimage 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fentoboardimage 1.4.1
File Size Uploaded Provenance
fentoboardimage-1.4.1.tar.gz 2.9 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fentoboardimage 1.4.1
File Interpreter ABI Platform
fentoboardimage-1.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 2.9 MB

Release files / fentoboardimage-1.4.1.tar.gz

Download URL fentoboardimage-1.4.1.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
895ae478da4dcd30bfe2525078344d24b307ee6ed1b4e07ff69da7a7012158a1
BLAKE2b-256 checksum
How to use checksums
2976f5ecf19f64323bae3c22872bf79e3d8975ffafb1f5255c189bbce9aee451
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fentoboardimage-1.4.1-py3-none-any.whl

Download URL fentoboardimage-1.4.1-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ecd2ccb905b3e7fa705f1c0d6b909b548c2f0e33777f3d77e947b9fe9d3bb4f9
BLAKE2b-256 checksum
How to use checksums
64196802fddf5292565d39d699cfb2c5c3ddd258b1a385d4d05d746b23bd8484
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fentoboardimage 1.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page