Skip to main content

Python bindings for Chafa. Visualize images with text in python.

Project description

chafa.py

The snakes don't bite! (I think...)

Docs | Tutorial | Examples

What is this?

Chafa is a wonderful command-line utility, created by Hans Petter Jansson, for visualizing images in the terminal. In Jansson's own words:

The future is (still) now!

The premier UX of the 21st century just got a little better: With chafa, you can now view very, very reasonable approximations of pictures and animations in the comfort of your favorite terminal emulator. The power of ANSI X3.64 compels you!

chafa.py is a python wrapper for the chafa library so you can use rad graphics in your (undoubtedly pretty cool) Python applications!

chafa.py tries to be very pythonian (I think that's a word) in the sense that most getter and setter functions are simply made to be attributes of Python objects.

Example

Here is a picture of a cute snake rendered to text using chafa.py:

And here is the code that printed this image. For more examples, head on over to the docs at chafapy.mage.black.

from chafa import *
from chafa.loader import Loader

# The font ratio of JetBrains Mono (width/height)
FONT_RATIO = 11/24

# Create a canvas config
config = CanvasConfig()

# Configure the canvas geometry
config.width  = 40
config.height = 40

# Load the snake
image = Loader("./snake.jpg")

# Configure the ideal canvas geometry based on our FONT_RATIO
config.calc_canvas_geometry(
   image.width,
   image.height,
   FONT_RATIO
)

# Init the canvas
canvas = Canvas(config)

# Draw to the canvs
canvas.draw_all_pixels(
   image.pixel_type,
   image.get_pixels(),
   image.width, image.height,
   image.rowstride
)

# Print the output
output = canvas.print()

print(output.decode())

How do I get it?

First, you will need to install chafa. This should be fairly straight forward since chafa packages are available for most linux distributions.

If you want to use the included Loader class to load images for using with chafa.py, you will also need the MagickWand C-library.

From PyPi

Chafa.py is available on PyPi. You can install it by running

pip install chafa.py

From source

If you want, you can install and play around with this package by cloning the repo and building it yourself

python -m build

in the root of the repository. This will build a distribution file in a new folder: dist/ called something like chafa_py-[version].gz. You can then install this file with pip by running

pip install ./dist/chafa_py-[version].tar.gz

Dependencies

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

chafa.py-1.0.0.post2.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

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

chafa.py-1.0.0.post2-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file chafa.py-1.0.0.post2.tar.gz.

File metadata

  • Download URL: chafa.py-1.0.0.post2.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.9

File hashes

Hashes for chafa.py-1.0.0.post2.tar.gz
Algorithm Hash digest
SHA256 f2d1ff0ac5e9ce67f20eedaa33fa3037a13af932b1f9d869ed73f41f63087e10
MD5 3b3fc0113dfd16d6fd0efe3824ccbc84
BLAKE2b-256 03a4568c65cfd3f3d500b2080b76e2567cd181e4e822af42744331df02c70132

See more details on using hashes here.

File details

Details for the file chafa.py-1.0.0.post2-py3-none-any.whl.

File metadata

  • Download URL: chafa.py-1.0.0.post2-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.9

File hashes

Hashes for chafa.py-1.0.0.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f279e030967186dee88586550918c022e39402ca762c42375d4f66644f4d349
MD5 64975e3329ce1691b1efb821d1293bb7
BLAKE2b-256 58148cfb84cf7d0c55c70eae6f2e73f4d4564ac07e9e78069b9833a011a34041

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