Images for your terminal.

imeji

イメジ ー Images for the terminal

demo

GoReportCard GoDoc

imeji is a lightweight alternative to the awesome chafa. It is written in go and can be easily embedded into tools. imeji takes a image as input and creates a sequence of characters and ansi color sequences resulting in a terminal printable images.

Why not use chafa?

If you can install chafa it should be preferred, as it is more advanced, faster and just awesome! But if you want to include terminal image output in your go application and don't want to ship chafa as external dependency imeji might be worth a try.

CLI

イメジ :: Images for the terminal ー by BigJk
 _                 _ _
(_)_ __ ___   ___ (_|_)
| | '_ ` _ \ / _ \| | |
| | | | | | |  __/| | |
|_|_| |_| |_|\___|/ |_|
                |__/
_________________________________________

  -font-scale float
    	vertical font scaling value (default: 0.8)
  -force-full-color
    	forces full color output
  -help
    	print help
  -input string
    	input image path
  -max-width int
    	sets the max width of the output (in cells) and keeps the aspect ratio
  -size string
    	size in terminal cells (e.g. 100x20)
  -symbols string
    	which symbole sets to use (blocks, blocks_simple, blocks_adv, ascii, misc) (default "blocks")

Install imeji command

go install github.com/BigJk/imeji/cmd/imeji@latest

Go Library

go get github.com/BigJk/imeji

Example

// Print directly to stdout and detect terminal capabilities:
imeji.File(os.Stdout, "./image.png", imeji.WithMaxWidth(100))

// Convert to string with full color support:
text, _ := imeji.FileString("./image.png", imeji.WithTrueColor())
fmt.Println(text)

Technique

I didn't find a good written reference on the technique used by Chafa and other tools so here is a basic overview. Its important to know that in the terminal we are limited to a single foreground and background color per character. That means for each cell in the terminal we need to find the best character and foreground, background pair with the least "error" (difference) to the real picture.

Pattern

The basic idea is that you can map a single character in terminal to 8x8 pixels of a real image. For each character that wants to be used in a terminal picture the pattern needs to be created. A pattern can easily be defined by an 8 line string. The pattern defines which pixels are set to the foreground color and which to the background color.

See /charmaps/blocks.go and you will quickly get the idea.

Examples:

  • Char: █ (Full Block -> All pixel set)
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
  • Char: !
________
___X____
___X____
___X____
___X____
________
___X____
________

Procedure

Now that we know how to define the pattern for a character we can convert a image to terminal printable characters.

  1. Chunk the image into 8x8 pixel chunks
  2. For each pixel chunk:
    1. Randomly select a few (foreground, background) pairs from the pixels in the chunk
    2. For all the pairs test all characters and calculate the error to the real pixels
    3. Return the pair and character with the least error
  3. For each chunk print the selected character with the chosen foreground and background

Further Work

  • Better handling of alpha channel
  • Use assembler with SIMD instructions to improve pixel to pattern diffing performance
Owner
Daniel S.
Can't get enough of programming 🖤
Daniel S.
Similar Resources

The personal information dashboard for your terminal

The personal information dashboard for your terminal

WTF (aka 'wtfutil') is the personal information dashboard for your terminal, providing at-a-glance access to your very important but infrequently-need

Dec 31, 2022

Advanced ANSI style & color support for your terminal applications

Advanced ANSI style & color support for your terminal applications

termenv lets you safely use advanced styling options on the terminal. It gathers information about the terminal environment in terms of its ANSI & col

Dec 31, 2022

GIFs in your terminal

GIFs in your terminal

gifwrap GIFs in your terminal. Install Download the latest binary or install with Go: go install github.com/liamg/gifwrap/cmd/gifwrap@latest Usage Usa

Jan 2, 2023

Share your terminal as a web application

Share your terminal as a web application

GoTTY - Share your terminal as a web application GoTTY is a simple command line tool that turns your CLI tools into web applications. Installation Dow

Jan 8, 2023

Typing test in your terminal

Typing test in your terminal

Typer Typing test in your terminal Installation go get github.com/maaslalani/typer/cmd/typer Usage To begin a typing test simply type typer. This wil

Jan 6, 2023

🐙🐱🖥️ GitHub stats in your terminal

🐙🐱🖥️ GitHub stats in your terminal

🐙 🐱 🖥️ octotui - GitHub stats in terminal Inspired by metrics & github-profile-summary-cards & github-tui 💖 Data - irevenko/octostats TUI - termui

Dec 25, 2022

Slack client for your terminal

Slack client for your terminal

slack-term A Slack client for your terminal. Installation Binary installation Download a compatible binary for your system. For convenience, place sla

Dec 30, 2022

some dancing gophers in your terminal

some dancing gophers in your terminal

gopherdance some dancing gophers in your terminal, my followup to .. heres how I make these files.. find a nice image, or animated gif that you want t

Mar 23, 2022

espnwrapper to track real time scores for your fav match... in a terminal while working.

espnwrapper to track real time scores for your fav match... in a terminal while working.

An espncricinfo wrapper written in go to track scores in real time and in the cmd/cli you can find the Command Line Interface wrapped over this wrapper.

Mar 13, 2022
Images for your terminal.
Images for your terminal.

imeji イメジ ー Images for the terminal imeji is a lightweight alternative to the awesome chafa. It is written in go and can be easily embedded into tools

May 9, 2023
Pi-fetch - get a summary of your pi-hole stats from your terminal

pi-fetch get a summary of your pi-hole stats from your terminal _ ___ _ _ ___|_|___| _|___| |_ ___| |_ | . | |___| _| -_| _

Jan 9, 2022
Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal.
Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal.

Stonks is a terminal based stock visualizer and tracker. Installation Requirements: golang >= 1.13 Manual Clone the repo Run make && make install Pack

Dec 16, 2022
Command line tool to copy images from a camera SD card to your hard drive

Command line tool to copy images from a camera SD card to your hard drive

Nov 26, 2021
Are you programming and suddenly your stomach is rumbling? No problem, order your Ifood without leaving your favorite text editor ❤️

vim-ifood Você ta programando e de repente bateu aquela fome? Sem problemas, peça seu Ifood sem sair do seu editor de texto favorito ❤️ Are you progra

Jun 2, 2022
gomerge is a tool to quickly bulk merge several pull requests from your terminal.
gomerge is a tool to quickly bulk merge several pull requests from your terminal.

Gomerge is a tool to quickly enable you to bulk merge Github pull requests from your terminal. The intention of this tool is to simplfy, and eventually automate the merging of github pull requests. This tool should be able to run on most systems.

Dec 28, 2022
YouTube client on your terminal

MeowTube YouTube client on your terminal Table of Contents About Getting Started Usage Contributing About MeowTube is a CLI (Command Line Interface) t

Jul 29, 2022
🎄 A Christmas tree right from your terminal!
🎄 A Christmas tree right from your terminal!

ctree ?? A Christmas tree right from your terminal! ?? Demo ⌛ No Refresh Don't want the tree to refresh every 2 seconds? Easy! Just add the --no-refre

Dec 20, 2022
❓🖼 Find the anime scene by image using your terminal
❓🖼 Find the anime scene by image using your terminal

What Anime CLI ❓ ?? > This application is basically a ?? wrapper around trace.moe PREVIEW Usage ?? Get Anime By Image File ?? what-anime file anime.jp

Jan 2, 2023
Pi-hole data right from your terminal. Live updating view, query history extraction and more!
Pi-hole data right from your terminal. Live updating view, query history extraction and more!

Pi-CLI Pi-CLI is a command line program used to view data from a Pi-Hole instance directly in your terminal.

Dec 12, 2022