Awesome
<div align="center"> <h1><b>Term-Image</b></h1> <p> <img src="https://raw.githubusercontent.com/AnonymouX47/term-image/92ff4b2d2e4731be9e1b2ac7378964ebed9f10f9/docs/source/resources/logo.png" height="200"> </p> <p> <b>Display images in the terminal with Python</b> </p> <p> 📖 <a href='https://term-image.readthedocs.io'>Docs</a> ║ 🏫 <a href='https://term-image.readthedocs.io/en/stable/start/tutorial.html'>Tutorial</a> </p> <p> <a href='https://pypi.org/project/term-image/'> <img src='https://img.shields.io/pypi/v/term-image.svg'> </a> <a href='https://pepy.tech/project/term-image'> <img src="https://pepy.tech/badge/term-image/month"> </a> <a href='https://pypi.org/project/term-image/'> <img src='https://img.shields.io/pypi/pyversions/term-image.svg'> </a> <a href='https://github.com/psf/black'> <img src='https://img.shields.io/badge/code%20style-black-000000.svg'> </a> <a href='https://github.com/AnonymouX47/term-image/actions/workflows/test.yml'> <img src='https://github.com/AnonymouX47/term-image/actions/workflows/test.yml/badge.svg'> </a> <a href='https://htmlpreview.github.io/?https://github.com/AnonymouX47/term-image/blob/python-coverage-comment-action-data/htmlcov/index.html'> <img src='https://raw.githubusercontent.com/AnonymouX47/term-image/python-coverage-comment-action-data/badge.svg'> </a> <a href='https://term-image.readthedocs.io'> <img src='https://readthedocs.org/projects/term-image/badge/?version=latest' alt='Documentation Status' /> </a> <img src="https://img.shields.io/github/last-commit/AnonymouX47/term-image"> <a href="https://twitter.com/intent/tweet?text=Display%20images%20in%20the%20terminal%20with%20Python&url=https://github.com/AnonymouX47/term-image&hashtags=developers,images,terminal,python"> <img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=social"> </a> </p> </div>Contents
- Installation
- Features
- Demo
- Quick Start
- Usage
- Contribution
- Planned Features
- Known Issues
- FAQs
- Credits
- Sponsor This Project
⚠️ NOTICE!!! ⚠️
The image viewer (CLI and TUI) has been moved to termvisage.
Installation
Requirements
-
Operating System: Unix / Linux / Mac OS X / Windows (limited support, see the FAQs)
-
Python >= 3.8
-
A terminal emulator with any of the following:
- support for the Kitty graphics protocol.
- support for the iTerm2 inline image protocol.
- full Unicode support and direct-color (truecolor) support
Plans to support a wider variety of terminal emulators are in motion (see Planned Features).
Steps
The latest stable version can be installed from PyPI with:
pip install term-image
The development version can be installed with:
pip install git+https://github.com/AnonymouX47/term-image.git
Supported Terminal Emulators
See here for a list of tested terminal emulators.
If you've tested this library on any other terminal emulator that meets the requirements for any of the render styles, please mention the name (and version) in a new thread under this discussion.
Also, if you have any issue with terminal support, you may report or check information about it in the discussion linked above.
Features
- Multiple image formats (basically all formats supported by
PIL.Image.open()
) - Multiple image source types: PIL image instance, local file, URL
- Multiple image render styles (with automatic support detection)
- Support for multiple terminal graphics protocols: Kitty, iTerm2
- Exposes various features of the protocols
- Transparency support (with multiple options)
- Animated image support (including transparent ones)
- Multiple formats: GIF, WEBP, APNG (and possibly more)
- Fully controllable iteration over rendered frames of animated images
- Image animation with multiple parameters
- Integration into various TUI / terminal-based output libraries.
- Terminal size awareness
- Automatic and manual image sizing
- Horizontal and vertical alignment
- Automatic and manual font ratio adjustment (to preserve image aspect ratio)
- and more... 😁
Demo
Check out this image viewer based on this library.
Quick Start
Creating an instance
-
Initialize with a file path:
from term_image.image import from_file image = from_file("path/to/image.png")
-
Initialize with a URL:
from term_image.image import from_url image = from_url("https://www.example.com/image.png")
-
Initialize with a PIL (Pillow) image instance:
from PIL import Image from term_image.image import AutoImage img = Image.open("path/to/image.png") image = AutoImage(img)
Drawing/Displaying an Image
There are two basic ways to draw an image to the terminal screen:
-
Using the
draw()
method:image.draw()
NOTE:
draw()
has various parameters for render formatting. -
Using
print()
with an image render output:print(image) # without formatting # OR print(f"{image:>200.^100#ffffff}") # with formatting
For animated images, only the former animates the output, the latter only draws the current frame.
See the tutorial for a more detailed introduction.
Usage
<p align="center"><b> 🚧 Under Construction - There will most likely be incompatible changes between minor versions of <a href='https://semver.org/spec/v2.0.0.html#spec-item-4'>version zero</a>! </b></p>If you want to use this library in a project while it's still on version zero, ensure you pin the dependency to a specific minor version e.g >=0.4,<0.5
.
See the docs for the User Guide and API Reference.
Contribution
Please read through the guidelines.
For code contributions, you should also check out the Planned Features. If you wish to work on any of the listed features/improvements, please click on the linked issue or go through the issues section and join in on an ongoing discussion about the task or create a new issue if one hasn't been created yet, so that the implementation can be discussed.
Hint: You can filter issues by label or simply search using the features's description.
Thanks! 💓
Planned Features
See the milestones and open issues with the planned
label.
Known Issues
See here.
FAQs
See the FAQs section of the docs.
Credits
The following projects have been (and are still) crucial to the development of this project:
- Pillow by Fredrik Lundh, Jeffrey A. Clark (Alex) and contributors
- Requests by Kenneth Reitz and others
The logo was composed using resource(s) from the following source(s):
This project started as img by Pranav Baburaj (but the author had no intentions to take it any further).
Sponsor This Project
<a href="https://www.buymeacoffee.com/anonymoux47" target="_blank"> <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" > </a>Any amount will go a long way in aiding the progress and development of this project. Thank you! 💓