Skip to main content

Convert images to unicode based on font templates. Especially usable in terminal.

Project description

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.

pip install img2unicode

Usage

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. Optimizes foreground color for all Unicode rendered in single cell. Same, but does't use terminal colors.
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 ~5Hz ~1Hz ~2Hz
O(S) O(S*T) O(S*log(T)) O(S*log(T))

Where S is the number of 16x8 pixel samples to optimize for and T is the number of templates.

More samples

To see how other optimizers compare to each other, see examples/README.md.

To see more eyecandy of photos, videos and plots, see the matrach/img2unicode-deoms repo

TODO

[ ] - write more docs, document code [ ] - describe how it works in readme [ ] - solve foreground & background optimization sublinear in templates

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

img2unicode-0.1a2.tar.gz (20.9 MB view details)

Uploaded Source

Built Distribution

img2unicode-0.1a2-py3-none-any.whl (20.9 MB view details)

Uploaded Python 3

File details

Details for the file img2unicode-0.1a2.tar.gz.

File metadata

  • Download URL: img2unicode-0.1a2.tar.gz
  • Upload date:
  • Size: 20.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.29.0 CPython/3.7.3

File hashes

Hashes for img2unicode-0.1a2.tar.gz
Algorithm Hash digest
SHA256 98bb7724b5ca01349f7cfb3bf221703c06588413833b436d7ef1057c3896a9fd
MD5 69912b5ad53c4974f5ee3c1981a8dd4a
BLAKE2b-256 37b6d4df7458fadc77268c1a0ad5aa3e06e177656e991c522c500187ed2fa0ad

See more details on using hashes here.

File details

Details for the file img2unicode-0.1a2-py3-none-any.whl.

File metadata

  • Download URL: img2unicode-0.1a2-py3-none-any.whl
  • Upload date:
  • Size: 20.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.29.0 CPython/3.7.3

File hashes

Hashes for img2unicode-0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 bf3a81c3b62f7a227dbd793336c81b5536a98409d9459300c35877395e6fc77c
MD5 1668329740b73f8fc68610bd3b69b59a
BLAKE2b-256 aa38052a3bd7c1e6dfa81d34e6a6663dba9547ed0b715f81c01f55f727c3349a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page