Display images in the terminal
Project description
Contents
- Installation
- Features
- CLI/TUI Quick Start
- Library Quick Start
- Usage
- Contribution
- WIP
- TODO
- Known Issues
- FAQs
Installation
Requirements
- Operating System: Unix / Linux / MacOS X / Windows (partial support, see the FAQs)
- Python >= 3.7
- A Terminal emulator with full Unicode support and ANSI 24-bit color support
- Plans are in place to support a wider variety of terminal emulators, whether not meeting or surpassing these requirements (see here).
Steps
The latest stable version can be installed from PyPI using pip
:
pip install term-image
The development version can be installed thus: Clone this repository, then navigate into the project directory in a terminal and run:
pip install .
Supported Terminal Emulators
See here for a list of tested terminal emulators.
If you've tested term-img
on any other terminal emulator that meets all requirements, please mention the name in a new thread under this discussion.
Also, if you're having an issue with terminal support, you may report or view information about it in the discussion linked above.
Features
Library features
- Multiple image format support
- Basically supports all formats supported by
PIL.Image.open()
- Basically supports all formats supported by
- Multiple image sources (PIL image, local file, URL)
- Transparency support (with multiple options)
- Animated image support (including transparent ones)
- Fully controllable and efficient iteration over frames of animated images
- Image animation with controllable parameters
- Terminal size awareness
- Variable image size
- Automatic image sizing; best fit within the terminal window or a given size
- Variable image scale
- Horizontal and vertical alignment/padding
- Font-ratio adjustment
- and more... :grin:
CLI/TUI features
- Basically everything the library supports
- Individual image display
- Browse multiple images
- Browse directories (recursively) [TUI]
- Image grids [TUI]
- Context-based controls [TUI]
- Dynamic controls (context actions are disabled and enabled dynamically) [TUI]
- Customizable controls and configuration options
- Automatic adjustment upon terminal resize [TUI]
- Image deletion [TUI]
- Smooth and fairly performant experience
- Takes advantage of both concurrency and parallelism
- Notification system
- Detailed logging system
- and more... :grin:
CLI/TUI Quick Start
Click to expand
From a local image file
term-img path/to/image.png
From a URL
term-img https://www.example.com/image.png
If the image is animated (GIF, WEBP), the animation is infinitely looped by default but can be stopped with Ctrl-C
.
By default, if multiple sources or at least one directory is given, the TUI (Text-based/Terminal User Interface) is launched to navigate through the images (and/or directories).
NOTE: python -m term_img
can be used as an alternative to the term-img
command (take note of the underscore VS hyphen).
Library Quick Start
Creating an instance
Click to expand
from term_img.image import TermImage
image = TermImage.from_file("path/to/image.png")
You can also use a URL if you don't have the file stored locally
from term_img.image import TermImage
image = TermImage.from_url("https://www.example.com/image.png")
The library can also be used with PIL images
from PIL import Image
from term_img.image import TermImage
img = Image.open("path/to/image.png")
image = TermImage(img)
Rendering an image
Click to expand
Rendering an image, in this context, is simply the process of converting it into text (a string). There are two ways to render an image:
1. Unformatted
str(image)
Renders the image without padding/alignment and with transparency enabled.
2. Formatted
format(image, "|200.^100#ffffff")
Renders the image with:
- center horizontal alignment
- a padding width of 200 columns
- top vertical alignment
- a padding height of 70 lines
- transparent background replaced with a white (
#ffffff
) background
f"{image:>._#.5}"
Renders the image with:
- right horizontal alignment
- automatic padding width (the current terminal width minus horizontal allowance)
- bottom vertical alignment
- automatic padding height (the current terminal height minus vertical allowance)
- transparent background with 0.5 alpha threshold
"{:1.1#}".format(image)
Renders the image with:
- center horizontal alignment (default)
- no horizontal padding, since
1
must be less than or equal to the image width - middle vertical alignment (default)
- no vertical padding, since
1
is less than or equal to the image height - transparency disabled (black background)
Drawing/Displaying an image to/in the terminal
Click to expand
There are two ways to draw an image to the terminal screen.
1. The draw()
method
image.draw()
NOTE: TermImage.draw()
method has various parameters for alignment/padding, transparency and animation control.
2. Using print()
with an image render output (i.e printing the rendered string)
print(image) # Uses str()
OR
print(f"{image:>200.^100#ffffff}") # Uses format()
For animated images, only the first method can animate the output, the second only outputs the current frame.
NOTE: All the above examples use automatic sizing and default scale.
Usage
Library
See the tutorial for a more detailed introduction and the reference for full descriptions and details of the available features.
PLEASE NOTE: This project is currently at a stage where the public API might change without warning but significant changes will always be specified in the changelog.
CLI (Command-Line Interface)
Run term-img --help
to see the full usage info and list of options.
TUI (Text-based/Terminal User Interface)
The controls are context-based and displayed at the bottom of the terminal window.
Pressing the F1
key (in most contexts) brings up a help menu describing the available controls (called actions) in that context.
The TUI controls can be configured by modifying the config file ~/.term_img/config.json
. See the Configuration section.
Here is a config file with Vim-style key-bindings (majorly navigation). Remember to rename the file to config.json
.
Contribution
If you've found any bug or want to suggest a new feature, please open a new issue with proper description, after browsing/searching through the existing issues and making sure you won't create a duplicate.
For code contributions, please make sure you read through the guidelines.
Also, check out the WIP and TODO sections below. If you wish to work on any of the listed tasks, please go through the issues tab 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 task's name or description.
For anything other than the above (such as questions or anything that would fit under the term "discussion"), please open a new discussion instead.
Thanks! :heart:
WIP
- Change of image sizing unit (See #16)
- Support for terminal graphics protocols (See #23)
- Support for more text-based rendering styles
- Performace Improvements
TODO
Check here for the library and here for the image viewer.
Known Issues
Check here for the library and here for the image viewer.
FAQs
See the FAQs section of the docs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for term_image-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71487cce1974097e4610f6fff30777a02902904d4b9621f43a3b0c160ee560f |
|
MD5 | dbbf885230191a7e113e3a257f3770d6 |
|
BLAKE2b-256 | 188634b8b7fb7438f805cb98144f4b3826edd20c9661fe21f19b84367fab27f0 |