Skip to main content

A Rich-compatible library for writing pixel images and ASCII art to the terminal.

Project description

Rich Pixels

A Rich-compatible library for writing pixel images and other colourful grids to the terminal.

Installation

Get rich-pixels from PyPI.

pip install rich-pixels

Basic Usage

Images

Image from a file

You can load an image file from a path using from_image_path:

from rich_pixels import Pixels
from rich.console import Console

console = Console()
pixels = Pixels.from_image_path("pokemon/bulbasaur.png")
console.print(pixels)

Pillow image object

You can create a PIL image object yourself and pass it in to from_image.

from rich_pixels import Pixels
from rich.console import Console
from PIL import Image

console = Console()

with Image.open("path/to/image.png") as image:
    pixels = Pixels.from_image(image)

console.print(pixels)

Using this approach means you can modify your PIL Image beforehard.

ASCII Art

You can quickly build shapes using a tool like asciiflow, and apply styles the ASCII characters. This provides a quick way of sketching out shapes.

from rich_pixels import Pixels
from rich.console import Console

console = Console()

# Draw your shapes using any character you want
grid = """\
     xx   xx
     ox   ox
     Ox   Ox
xx             xx
xxxxxxxxxxxxxxxxx
"""

# Map characters to different characters/styles
mapping = {
    "x": Segment(" ", Style.parse("yellow on yellow")),
    "o": Segment(" ", Style.parse("on white")),
    "O": Segment(" ", Style.parse("on blue")),
}

pixels = Pixels.from_ascii(grid, mapping)
console.print(pixels)

Using with Textual

Pixels can be integrated into Textual applications just like any other Rich renderable.

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

rich_pixels-3.0.1.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

rich_pixels-3.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file rich_pixels-3.0.1.tar.gz.

File metadata

  • Download URL: rich_pixels-3.0.1.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for rich_pixels-3.0.1.tar.gz
Algorithm Hash digest
SHA256 4a81977d45437ce5009cdcaf70af80256c3bdfab870e87ab802c577ba4133235
MD5 576f1cbf3809df1225462fec9b534c91
BLAKE2b-256 31716d5cd4b8d67cd49366eda19aaf37f20094ce562223a91166109202590237

See more details on using hashes here.

File details

Details for the file rich_pixels-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: rich_pixels-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for rich_pixels-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e82c5aa0d00885609675494f16e1ef814c68fa795634f1d6917cae9159b755e1
MD5 2f97f8332c3b1534d2d2c0a17e612673
BLAKE2b-256 08727264494bc0944db1166b73c88f19d9ddfc584dbbc77c210cd0f52f59c511

See more details on using hashes here.

Supported by

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