Skip to main content

A small, single file, package to convert a PIL image into a Rich / Textual compatible ascii image.

Project description

Textual ASCII image

A small, single file, package to convert a PIL image into a Rich / Textual compatible ascii image.

Why not another ascii library like ascii-magic?

Textual / rich don't use ANSI colours or codes. instead using [] to define colours.

[red]hello[/red] -> hello

Installation

pip install textual-ascii-image

Requirements

  • Pillow - an image library

Usage

	from ascii_image import to_ascii
	from PIL import Image


	image = Image.Image("path/to/image.png")
	ascii_image = to_ascii(image)

	#Textual
	from textual.app import App
	from textual.widgets import Label
	class App(App):
		def compose(self):
			yield Label(ascii_image)

	#######################################

	#Rich
	from rich import print
	print(ascii_image)

img

Docs

	def to_ascii(img: PIL.Image.Image, character: str = "▀", size: Optional[tuple[int,int]] = None, doubled: bool = True) -> str:
  • img: A Pillow image
  • size (Optional): used to resize image. (would recommend below 64x64)
  • character (Optional): The ASCII character.
    • defaults to if in doubled mode, or if not
  • doubled (Optional): decides if should sample two rows per column, or one

when in doubled mode, each character represents a top and bottom pixel

When not in doubled mode, each pixel takes up 2 characters horizontally.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

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

textual_ascii_image_magicmaana-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file textual_ascii_image_magicmaana-0.0.1.tar.gz.

File metadata

File hashes

Hashes for textual_ascii_image_magicmaana-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8f18f458e6eb3a7dee43bea5a9ddc0987c581f24f3d7787163bbf79ff85f1af2
MD5 67979e7bb67ec510b60ed7d4b9e73fc4
BLAKE2b-256 c507936cfcd6fe98ab1948bd8449d82a39e59a057b407e9269c655b56bc6d94a

See more details on using hashes here.

File details

Details for the file textual_ascii_image_magicmaana-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for textual_ascii_image_magicmaana-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a38f374d44b7014df5b40e04e2ac04e55b08626d711f950a079c26290d30c6cd
MD5 300e127f7830698709e2c8e36c039b82
BLAKE2b-256 17811fdd4ff4a86007f4e1c5ad4167860bbc353e280cc064ccc06c2a4af1d69e

See more details on using hashes here.

Supported by

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