Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darrenburns/rich-pixels
A Rich-compatible library for writing pixel images and ASCII art to the terminal.
https://github.com/darrenburns/rich-pixels
ascii ascii-art console rich terminal textual
Last synced: 6 days ago
JSON representation
A Rich-compatible library for writing pixel images and ASCII art to the terminal.
- Host: GitHub
- URL: https://github.com/darrenburns/rich-pixels
- Owner: darrenburns
- License: mit
- Created: 2022-11-07T23:53:36.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T09:50:15.000Z (4 months ago)
- Last Synced: 2025-02-04T22:32:04.281Z (7 days ago)
- Topics: ascii, ascii-art, console, rich, terminal, textual
- Language: Python
- Homepage:
- Size: 68.4 KB
- Stars: 275
- Watchers: 5
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-textualize-projects - Rich Pixels - A Rich-compatible library for writing pixel images and ASCII art to the terminal. (Community / Third Party Applications)
README
# 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`:
```python
from rich_pixels import Pixels
from rich.console import Consoleconsole = 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`.
```python
from rich_pixels import Pixels
from rich.console import Console
from PIL import Imageconsole = 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](https://asciiflow.com), and
apply styles the ASCII characters. This provides a quick way of sketching out shapes.```python
from rich_pixels import Pixels
from rich.console import Console
from rich.segment import Segment
from rich.style import Styleconsole = 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](https://github.com/Textualize/textual)
applications just like any other Rich renderable.