imgcat作为python api和cli
imgcat的Python项目详细描述
imgcat
imgcat cli,用python编写(还有python api)。
它可以与iTerm2一起工作,甚至可以在tmux内部工作。
安装和使用
pip install imgcat
命令行接口(类似于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:
>>>fromimgcatimportimgcat# 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))>>>importmatplotlib.pyplotasplt>>>fig,ax=plt.subplots();ax.plot([1,2,3,4,5])>>>imgcat(fig)
matplotlib后端:module://imgcat
MPLBACKEND="module://imgcat"pythondraw_matplotlib.py
>>>importmatplotlib>>>matplotlib.use("module://imgcat")>>>importmatplotlib.pyplotasplt>>>fig,ax=plt.subplots()>>>ax.text(0.5,0.5,"Hello World!");>>>fig.show()# an image shall be displayed on your terminal!
注释
- 目前,tmux 2.5+ cannot display big images。使用tmux<;=2.4或在tmux外部运行。
- TOdo:通用平台/模拟器支持(引入多个后端)
相关项目
- 原始实现:imgcat来自iterm2(有限的tmux支持)
- 通过Eric Dobson和@krtx有更好的tmux支持的修改版本
- node.js:term-img(不支持tmux)
- 转到:iterm2-imagetools(不支持tmux)