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

There are instructions on building chafa.py from source on Windows or Linux in the docs

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.2.tar.gz (3.2 MB view hashes)

Uploaded Source

Built Distributions

chafa.py-1.0.2-cp311-cp311-win_amd64.whl (1.7 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

chafa.py-1.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

chafa.py-1.0.2-cp311-cp311-macosx_12_0_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ ARM64

chafa.py-1.0.2-cp311-cp311-macosx_11_0_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ x86-64

chafa.py-1.0.2-cp311-cp311-macosx_10_16_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.16+ x86-64

chafa.py-1.0.2-cp311-cp311-macosx_10_16_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.16+ ARM64

chafa.py-1.0.2-cp310-cp310-win_amd64.whl (1.7 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

chafa.py-1.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

chafa.py-1.0.2-cp310-cp310-macosx_12_0_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ ARM64

chafa.py-1.0.2-cp310-cp310-macosx_11_0_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ x86-64

chafa.py-1.0.2-cp310-cp310-macosx_10_16_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.16+ x86-64

chafa.py-1.0.2-cp310-cp310-macosx_10_16_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.16+ ARM64

chafa.py-1.0.2-cp39-cp39-win_amd64.whl (1.7 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

chafa.py-1.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

chafa.py-1.0.2-cp39-cp39-macosx_12_0_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ ARM64

chafa.py-1.0.2-cp39-cp39-macosx_11_0_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ x86-64

chafa.py-1.0.2-cp39-cp39-macosx_10_16_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.16+ x86-64

chafa.py-1.0.2-cp39-cp39-macosx_10_16_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.16+ ARM64

chafa.py-1.0.2-cp38-cp38-win_amd64.whl (1.7 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

chafa.py-1.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

chafa.py-1.0.2-cp38-cp38-macosx_12_0_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.8 macOS 12.0+ ARM64

chafa.py-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ x86-64

chafa.py-1.0.2-cp38-cp38-macosx_10_16_x86_64.whl (870.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.16+ x86-64

chafa.py-1.0.2-cp38-cp38-macosx_10_16_arm64.whl (683.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.16+ ARM64

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