# img2unicode
A tool to display images as Unicode in your terminal.
The library is currently optimized for Ubuntu Mono font rendered by libvte (Gnome Terminal, Terminator etc.) i.e. it works on stock Ubuntu.
````bash
pip install img2unicode
imgcat image.jpg
````
## Usage
```python
import img2unicode
# Use Unicode Block Elements
optimizer = img2unicode.FastGenericDualOptimizer("block")
renderer = img2unicode.Renderer(default_optimizer=optimizer, max_h=60, max_w=160)
renderer.render_terminal('examples/obama.jpg', 'obama-block.txt')
# Pair Renderer to Optimizer
optimizer = img2unicode.FastGammaOptimizer("no_block")
renderer = img2unicode.GammaRenderer(default_optimizer=optimizer, max_h=60, max_w=160)
renderer.render_terminal('examples/obama.jpg', 'obama-noblock.txt')
pil_image = renderer.prerender('examples/obama.jpg')
pil_image.save('obama-rendered.png')
# Use own mask: it may be name from common masks (see source), slice or numpy bool array.
ascii_optimizer = img2unicode.FastGammaOptimizer(slice(32, 127), use_color=False)
# Get the characters, foreground and background colors. Use non-default optimizer.
chars, fores, backs = renderer.render_numpy('examples/obama.jpg', optimizer=ascii_optimizer)
```
## Optimizers
Here is a quick comparison of the most usable optimizers:
| FastQuadDualOptimizer() | FastGenericDualOptimizer ("block") | FastGammaOptimizer (charmask="no_block") | FastGammaOptimizer (charmask="no_block", use_color=False) |
| --- | --- | --- | ---
| Choses from 4-pixel characters like ▚ | Optimizes foreground/background for whole [Unicode Block Elements](https://en.wikipedia.org/wiki/Block_Elements). | Optimizes foreground color for all Unicode rendered in single cell. | Same, but does't use terminal colors. |
| ![](examples/obama/dual/quad.png) | ![](examples/obama/dual/fast-block.png) | ![](examples/obama/gamma/fast-noblock.png) | ![](examples/obama/gamma/fast-noblock-bw.png) |
| ![](examples/matplotlib/dual/quad.png) | ![](examples/matplotlib/dual/fast-block.png) | ![](examples/matplotlib/gamma/fast-noblock.png) | ![](examples/matplotlib/gamma/fast-noblock-bw.png) |
| Good color representation | Good color and crisper image | Crisp edges with black | Pure art, no color. |
| Foreground & background | Foreground & background | Just foreground | No color |
| ~5Hz | ~4Hz | ~1Hz | ~2Hz |
| O(S*T), T=7 | O(S*T), T=24 | O(S*log(T)), T=5553 | O(S*log(T)), T=5553 |
Where `S` is the number of 16x8 pixel samples to optimize for and `T` is the number of templates.
## See it yourself
Use the included `termview` script to browse images with all renderers:
```bash
termview examples/obama.jpg
```
![termview demo](examples/termview.gif)
or use `imgcat` to display an image in your terminal:
```bash
imgcat examples/obama.jpg
```
## More samples
To see how other optimizers compare to each other, see [examples/README.md](examples/README.md).
To see more eyecandy of photos, videos and plots, see the [matrach/img2unicode-deoms repo](https://github.com/matrach/img2unicode-demos)
# TODO
- [ ] write more docs, document code
- [ ] describe how it works in readme
- [ ] solve foreground & background optimization sublinear in templates
- [ ] add support for Unicode 13 Legacy Computing block
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:img2unicode-0.1a4.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
img2unicode-0.1a4.tar.gz (20个子文件)
img2unicode-0.1a4
PKG-INFO 4KB
bin
termview 13KB
imgcat 2KB
img2unicode
Ubuntu Mono.npz 19.66MB
utils.py 1KB
unicodeit.py 26KB
__init__.py 65B
gamma.py 6KB
templates.py 3KB
renderer.py 7KB
dual.py 8KB
setup.cfg 38B
img2unicode.egg-info
PKG-INFO 4KB
requires.txt 124B
not-zip-safe 1B
SOURCES.txt 438B
top_level.txt 12B
dependency_links.txt 1B
setup.py 1KB
README.md 3KB
共 20 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C++ primer 习题上半部分
- C#ASP.NET项目进度管理(甘特图表)源码 任务考核管理系统源码数据库 Access源码类型 WebForm
- 个人练习-练习版内网通?
- 支持向量机 - SVM支持向量机
- 可以识别视频语音自动生成字幕SRT文件的开源 Windows-GUI 软件工具.zip
- 基于SpringBoot框架和SaaS模式,立志为中小企业提供开源好用的ERP软件,目前专注进销存+财务+生产功能
- C#ASP.NET口腔门诊会员病历管理系统源码 门诊会员管理系统源码数据库 SQL2008源码类型 WebForm
- 微信Java开发工具包,支持包括微信支付、开放平台、公众号、企业微信、视频号、小程序等微信功能模块的后端开发
- 灰狼优化算法(Grey Wolf Optimizer,GWO)是一种群智能优化算法
- C语言课程设计项目之扫雷项目源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功