Skip to main content

uppercut-pixel-art-sheets

Pillow helpers for building indexed pixel-art sheets. It covers palettes with a reserved transparent index, stamping 1-bit patterns, drawing text with a built-in 5x7 bitmap font, drawing in a tile's own coordinates, packing tiles into a sheet grid with metadata, and saving indexed PNGs.

Install

pip install uppercut-pixel-art-sheets

Requires Python 3.10 or newer and Pillow 10 or newer.

Example

from PIL import ImageDraw
from uppercut_pixel_art_sheets import (
    build_sheet, draw_text, hex_to_rgb, new_indexed, save_indexed, snap_to_bits,
)

palette = [snap_to_bits(hex_to_rgb(c)) for c in ("#000000", "#f4e5ba", "#b63f3b", "#4fb9c3")]

def tile(label, color):
    im = new_indexed(16, 16)            # index 0 is transparent
    d = ImageDraw.Draw(im)
    d.rectangle((1, 1, 14, 14), fill=color)
    draw_text(d, label, 5, 4, 1)
    return label, im

sheet, meta = build_sheet([tile("A", 2), tile("B", 3), tile("C", 2)], cols=2, cell_w=16, cell_h=16, palette=palette)
save_indexed(sheet, palette, "sheet.png")
print(meta[1])   # {'index': 1, 'name': 'B', 'col': 1, 'row': 0, 'x': 16, 'y': 0, 'w': 16, 'h': 16}

Functions

Name What it does
hex_to_rgb(value) Parses #rrggbb.
snap_to_bits(color, bits=5) Rounds each channel to bits bits and back to 8, for console-style color depth.
new_indexed(width, height, fill=0) A palette-mode image filled with one index.
apply_palette(image, palette, *, transparency=0, size=256) Sets the palette, padded with black to size entries. transparency is a transparent index, a bytes object with one alpha per index, or None.
save_indexed(image, palette, path, *, transparency=0, size=256) Applies the palette, creates parent folders and saves an indexed PNG. Returns the path.
force_corner_transparent(image) Swaps the top-left pixel's color into index 0 and marks index 0 transparent. The picture looks the same.
quantize_indexed(image, colors=16, *, transparent_corner=True) Adaptive palette reduction, optionally followed by force_corner_transparent.
indexed_to_rgba(image, *, transparent_index=0) RGBA copy with one index made transparent.
stamp_pattern(draw, pattern, x, y, color, *, scale=1, ink="1") Draws each ink character of a list of strings as a block. Works on indexed and RGB images.
FONT_5X7 Glyph table for capitals, digits and punctuation (67 glyphs, no lowercase). It is generated from the font source in the bitmap-font package of this repository, the same one its C tables come from; _font5x7.py is generated, so change bitmap-font/data/bitmap-fonts.txt and run its generator instead of editing it.
draw_text(draw, text, x, y, color, *, font=FONT_5X7, spacing=6, scale=1) Draws upper-cased text, shows ? for unknown characters, returns the advance in pixels.
text_width(text, *, font=FONT_5X7, spacing=6, scale=1) Pixel width of a string.
cut_corner_box(draw, box, fill, outline=None) Rectangle with its corner pixels cut off.
Origin(draw, ox, oy) Offsets point, line, rect, ellipse, polygon, pattern and text by (ox, oy).
nearest_scale(image, factor) Whole-number nearest-neighbour upscale.
paste_cell(sheet, tile, col, row, cell_w, cell_h) Pastes a tile into the top-left of a grid cell.
build_sheet(tiles, cols, cell_w, cell_h, palette=None, *, fill=0, transparency=0, size=256) Packs tiles (images or (name, image) pairs) into a sheet and returns it with one metadata dict per tile. With a palette the sheet is indexed; without one it is RGBA.

Changes in 0.2.0

FONT_5X7 now comes from the shared font source. Thirteen glyphs were added (", $, &, *, ;, @, [, \, ], ^, a backtick, | and ~) and four changed shape to the version two of the three hand-drawn tables agreed on: D has square corners, J's hook is two rows tall, 6 has a three-pixel top and 9 a three-pixel bottom. Nothing was removed.

Errors

All functions raise ValueError for bad input: an image that is not in palette mode where one is required, a palette larger than size, a tile bigger than its cell, an empty tile list, a scale or factor below 1, or a malformed hex color.

License

MIT

Metadata

Release files for uppercut-pixel-art-sheets 0.2.0

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

Source distribution (sdist)

Source distribution for uppercut-pixel-art-sheets 0.2.0
File Size Uploaded Provenance Actions
uppercut_pixel_art_sheets-0.2.0.tar.gz 10.4 kB Without provenance Details for uppercut_pixel_art_sheets-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uppercut-pixel-art-sheets 0.2.0
File Interpreter ABI Platform Actions
uppercut_pixel_art_sheets-0.2.0-py3-none-any.whl Python 3 none any Details for uppercut_pixel_art_sheets-0.2.0-py3-none-any.whl

Total release size: 20.5 kB

Release files / uppercut_pixel_art_sheets-0.2.0.tar.gz

Download URL uppercut_pixel_art_sheets-0.2.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f4e6797f163525849be90edd4117f360bcd6a45981c583bae25a376362038dbc
BLAKE2b-256 checksum
How to use checksums
56c0e0bd7624b498007e0bfe113e7708a20366625d47a882656ee9ab463d92b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / uppercut_pixel_art_sheets-0.2.0-py3-none-any.whl

Download URL uppercut_pixel_art_sheets-0.2.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd17babb30a08174f3c2311cb78e2b9fa067ead10a506612aa60c5146c53273f
BLAKE2b-256 checksum
How to use checksums
cbfeb120a9fb6803dafa6a07b6bbc53a644e688bb60b7bfa848ae95632cb4b3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for uppercut-pixel-art-sheets 0.2.0

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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