GuardKenzie/chafa.py
소개
Python bindings for Chafa. Visualize images with text in python.
디자인 및 미디어What you can do
- ⚡ Modern and intuitive Python API
- 📖 Extensive documentation and a tutorial
- 📟 Generate text based approximations of images in (almost) any terminal emulator
- 6️⃣ Sixels, 😸 Kitty and 🍎 ITerm2 image protocols support
측정된 스타 증가
- in 24h
- +1
- in 7 days
- +1
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalWhat is this?
Have you ever wanted to display an image in your TUI Python application? Well, now you can!
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 cool Python applications! The chafa.py library tries to be intuitive and aims to produce very readable code.
Features include:
- ⚡ Modern and intuitive Python API
- 📖 Extensive documentation and a tutorial
- 📟 Generate text based approximations of images in (almost) any terminal emulator
- 6️⃣ Sixels, 😸 Kitty and 🍎 ITerm2 image protocols support
- 🐧 Linux, 🍎 MacOS (x86 and ARM), 🪟 Windows support
Example
Here is a picture of a cute snake rendered to text using chafa.py:
✏️ Code
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())
Where can I get it?
Chafa.py is available on PyPI. You can install it by running
pip install chafa.py
If you want to use the included Loader class to load images, you will also need to install MagickWand.
Dependencies
- Python 3.8 or later
Optional Dependencies
- MagickWand (for the Loader class)
📬 P.S. The snakes don't bite (I think...)
🐍🐍🐍🐍🐍관련 프로젝트 살펴보기
불러오는 중…