imgcat as Python API and CLI
Project description
imgcat
The imgcat CLI, written in Python (and Python API, too).
It works with iTerm2, and even inside tmux.
Installation and Usage
pip install imgcat
Command-line interface (similar to iTerm2's imgcat):
$ imgcat local_image.png
$ imgcat a.png b.png c.png
$ cat from_stdin.gif | imgcat
# height is 10 lines
$ imgcat a.png --height 10
Python API:
>>> from imgcat import imgcat
# from the content of image (e.g. buffer in python3, str in python2)
>>> imgcat(open("./local_image.png"))
# or numpy arrays!
>>> im = skimage.data.chelsea() # [300, 451, 3] ndarray, dtype=uint8
>>> imgcat(im, height=7)
# matplotlib, PIL.Image, etc.
>>> imgcat(Image.fromarray(im))
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(); ax.plot([1, 2, 3, 4, 5])
>>> imgcat(fig)
Matplotlib Backend: module://imgcat
MPLBACKEND="module://imgcat" python draw_matplotlib.py
>>> import matplotlib
>>> matplotlib.use("module://imgcat")
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.text(0.5, 0.5, "Hello World!");
>>> fig.show()
# an image shall be displayed on your terminal!
Notes
- Currently, tmux 2.5+ cannot display big images. Use tmux <= 2.4 or run outside tmux.
- TODO: General platform/emulator support (introduce multiple backends)
Related Projects
- Original implementation: imgcat from iTerm2 (limited tmux support)
- There are modified versions with better tmux support by Eric Dobson and by @krtx
- Node.js: term-img (no tmux support)
- Go: iterm2-imagetools (no tmux support)
License
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
imgcat-0.3.0.tar.gz
(8.6 kB
view details)
File details
Details for the file imgcat-0.3.0.tar.gz
.
File metadata
- Download URL: imgcat-0.3.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68008138f6fba30ab27d51737389c8889232e8a1b1c5f0c392458abedfbec4e5 |
|
MD5 | 5e495023efb39fabd8c6a51b1b826212 |
|
BLAKE2b-256 | 60e8dab903088a88ee0132240426b55ff87aebc69a958e7fb103ea70797cc21d |