• Stars
    star
    193
  • Rank 201,081 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command to convert from color text (ANSI or 256) to image.

textimg

test codecov

textimg is command to convert from color text (ANSI or 256) to image.
Drawn image keeps having colors of escape sequence.

Table of contents:

Usage

Simple examples

textimg $'\x1b[31mRED\x1b[0m' > out.png
textimg $'\x1b[31mRED\x1b[0m' -o out.png
echo -e '\x1b[31mRED\x1b[0m' | textimg -o out.png
echo -e '\x1b[31mRED\x1b[0m' | textimg --background 0,255,255,255 -o out.jpg
echo -e '\x1b[31mRED\x1b[0m' | textimg --background black -o out.gif

Output image format is PNG or JPG or GIF. File extention of -o option defines output image format. Default image format is PNG. if you write image file with > redirect then image file will be saved as PNG file.

With other commands

grep:

echo hello world | grep hello --color=always | textimg -o out.png

image

screenfetch:

screenfetch | textimg -o out.png

bat:

bat --color=always /etc/profile | textimg -o out.png

image

ccze:

ls -lah | ccze -A | textimg -o out.png

image

lolcat:

seq -f 'seq %g | xargs' 18 | bash | lolcat -f --freq=0.5 | textimg -o out.png

image

Rainbow examples

From ANSI color

textimg supports \x1b[30m notation.

colors=(30 31 32 33 34 35 36 37)
i=0
while read -r line; do
  echo -e "$line" | sed -r 's/.*/\x1b['"${colors[$((i%8))]}"'m&\x1b[m/g'
  i=$((i+1))
done <<< "$(seq 8 | xargs -I@ echo TEST)" | textimg -b 50,100,12,255 -o testdata/out/rainbow.png

Output is here.

Rainbow example

From 256 color

textimg supports \x1b[38;5;255m notation.

Foreground example is below.

seq 0 255 | while read -r i; do
  echo -ne "\x1b[38;5;${i}m$(printf %03d $i)"
  if [ $(((i+1) % 16)) -eq 0 ]; then
    echo
  fi
done | textimg -o 256_fg.png

Output is here.

256 foreground example

Background example is below.

seq 0 255 | while read -r i; do
  echo -ne "\x1b[48;5;${i}m$(printf %03d $i)"
  if [ $(((i+1) % 16)) -eq 0 ]; then
    echo
  fi
done | textimg -o 256_bg.png

Output is here.

256 background example

From 256 RGB color

textimg supports \x1b[38;2;255;0;0m notation.

seq 0 255 | while read i; do
  echo -ne "\x1b[38;2;${i};0;0m$(printf %03d $i)"
  if [ $(((i+1) % 16)) -eq 0 ]; then
    echo
  fi
done | textimg -o extrgb_f_gradation.png

Output is here.

RGB gradation example

Animation GIF

textimg supports animation GIF.

echo -e '\x1b[31mText\x1b[0m
\x1b[32mText\x1b[0m
\x1b[33mText\x1b[0m
\x1b[34mText\x1b[0m
\x1b[35mText\x1b[0m
\x1b[36mText\x1b[0m
\x1b[37mText\x1b[0m
\x1b[41mText\x1b[0m
\x1b[42mText\x1b[0m
\x1b[43mText\x1b[0m
\x1b[44mText\x1b[0m
\x1b[45mText\x1b[0m
\x1b[46mText\x1b[0m
\x1b[47mText\x1b[0m' | textimg -a -o ansi_fb_anime_1line.gif

Output is here.

Animation GIF example

Slide animation GIF

echo -e '\x1b[31mText\x1b[0m
\x1b[32mText\x1b[0m
\x1b[33mText\x1b[0m
\x1b[34mText\x1b[0m
\x1b[35mText\x1b[0m
\x1b[36mText\x1b[0m
\x1b[37mText\x1b[0m
\x1b[41mText\x1b[0m
\x1b[42mText\x1b[0m
\x1b[43mText\x1b[0m
\x1b[44mText\x1b[0m
\x1b[45mText\x1b[0m
\x1b[46mText\x1b[0m
\x1b[47mText\x1b[0m' | textimg -l 5 -SE -o slide_5_1_rainbow_forever.gif

Output is here.

Slide Animation GIF example

Using on Docker

You can use textimg on Docker. (DockerHub)

docker pull jiro4989/textimg
docker run -v $(pwd):/images -it jiro4989/textimg -h
docker run -v $(pwd):/images -it jiro4989/textimg Testあいうえお😄 -o /images/a.png
docker run -v $(pwd):/images -it jiro4989/textimg Testあいうえお😄 -s

or build docker image of local Dockerfile.

docker-compose build
docker-compose run textimg $'\x1b[31mHello\x1b[42mWorld\x1b[m' -s

Saving shortcut

textimg saves an image as t.png to $HOME/Pictures (%USERPROFILE% on Windows) with -s options. You can change this directory with TEXTIMG_OUTPUT_DIR environment variables.

textimg adds current timestamp to the file suffix when activate -t options.

$ textimg 寿司 -st

$ ls ~/Pictures/
t_2021-03-21-194959.png

And, textimg adds number to the file suffix when activate -n options and the file has existed.

$ textimg 寿司 -sn

$ textimg 寿司 -sn

$ ls ~/Pictures/
t.png  t_2.png

Installation

Linux users (Debian base distros)

wget https://github.com/jiro4989/textimg/releases/download/v3.1.9/textimg_3.1.9_amd64.deb
sudo dpkg -i ./*.deb

Linux users (RHEL compatible distros)

sudo yum install https://github.com/jiro4989/textimg/releases/download/v3.1.9/textimg-3.1.9-1.el7.x86_64.rpm

With Go

go get -u github.com/jiro4989/textimg/v3

Manual

Download binary from Releases.

Help

textimg is command to convert from colored text (ANSI or 256) to image.

Usage:
  textimg [flags]

Examples:
textimg $'\x1b[31mRED\x1b[0m' -o out.png

Flags:
  -g, --foreground string         foreground text color.
                                  available color types are [black|red|green|yellow|blue|magenta|cyan|white]
                                  or (R,G,B,A(0~255)) (default "white")
  -b, --background string         background text color.
                                  color types are same as "foreground" option (default "black")
  -f, --fontfile string           font file path.
                                  You can change this default value with environment variables TEXTIMG_FONT_FILE
  -x, --fontindex int             
  -e, --emoji-fontfile string     emoji font file
  -X, --emoji-fontindex int       
  -i, --use-emoji-font            use emoji font
  -z, --shellgei-emoji-fontfile   emoji font file for shellgei-bot (path: "/usr/share/fonts/truetype/ancient-scripts/Symbola_hint.ttf")
  -F, --fontsize int              font size (default 20)
  -o, --out string                output image file path.
                                  available image formats are [png | jpg | gif]
  -t, --timestamp                 add time stamp to output image file path.
  -n, --numbered                  add number-suffix to filename when the output file was existed.
                                  ex: t_2.png
  -s, --shellgei-imagedir         image directory path for shellgei-bot (path: "/images/t.png")
  -a, --animation                 generate animation gif
  -d, --delay int                 animation delay time (default 20)
  -l, --line-count int            animation input line count (default 1)
  -S, --slide                     use slide animation
  -W, --slide-width int           sliding animation width (default 1)
  -E, --forever                   sliding forever
      --environments              print environment variables
      --slack                     resize to slack icon size (128x128 px)
  -h, --help                      help for textimg
  -v, --version                   version for textimg

Fonts

Default font path

Default fonts that to use are below.

OS Font path
Linux /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc
Linux /usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc
MacOS /System/Library/Fonts/AppleSDGothicNeo.ttc
iOS /System/Library/Fonts/Core/AppleSDGothicNeo.ttc
Android /system/fonts/NotoSansCJK-Regular.ttc
Windows C:\Windows\Fonts\msgothic.ttc

You can change this font path with environment variables TEXTIMG_FONT_FILE .

Examples.

export TEXTIMG_FONT_FILE=/usr/share/fonts/TTF/HackGen-Regular.ttf

Emoji font (image file path)

textimg needs emoji image files to draw emoji. You have to set TEXTIMG_EMOJI_DIR environment variables if you want to draw one. For example, run below.

# You can clone your favorite fonts here.
sudo git clone https://github.com/googlefonts/noto-emoji /usr/local/src/noto-emoji
export TEXTIMG_EMOJI_DIR=/usr/local/src/noto-emoji/png/128
export LANG=ja_JP.UTF-8
echo Test👍 | textimg -o emoji.png

Emoji example

Emoji font (TTF)

textimg can change emoji font with TEXTIMG_EMOJI_FONT_FILE environment variables and set -i option. For example, swicthing emoji font to Symbola font.

export TEXTIMG_EMOJI_FONT_FILE=/usr/share/fonts/TTF/Symbola.ttf
echo あ😃a👍!👀ん👄 | textimg -i -o emoji_symbola.png

Symbola emoji example

Tab Completions

You can use TAB completions on your shell.

Bash

Run below.

sudo cp -p completions/bash/textimg /usr/share/bash-completion/completions/textimg

Zsh

Run below.

sudo cp -p completions/zsh/textimg /usr/share/zsh/functions/Completion/_textimg

# or
# sudo cp -p completions/zsh/textimg {path to your $fpath}

Fish

Run below.

ln -sfn completions/fish/textimg.fish $HOME/.config/fish/completions/textimg.fish

Development

go version go1.17 linux/amd64

How to build

You run below.

make setup-tools
make

I didn't test on Windows.

How to test

make test

# docker
make docker-build
make docker-test

See also

More Repositories

1

ojosama

テキストを壱百満天原サロメお嬢様風の口調に変換します
Go
381
star
2

setup-nim-action

Set up your GitHub Actions workflow with a specific version of Nim
JavaScript
93
star
3

websh

シェル芸botをWebで使えるようにしたNim製Webアプリ
Nim
67
star
4

slotchmod

slotchmod changes file permission with a slot.
Go
57
star
5

nimjson

nimjson generates nim object definitions from json documents.
Nim
49
star
6

ojosama-web

テキストを壱百満天原サロメお嬢様風の口調に変換するWebアプリ
HTML
41
star
7

faker

Faker is a Nim package that generates fake data for you.
Nim
39
star
8

build-deb-action

build-deb-action builds a simple debian package.
Nim
37
star
9

monit

The task runner. Run tasks and watch file changes with custom paths.
Nim
27
star
10

nimtetris

A terminal tetris in Nim.
Nim
23
star
11

relma

GitHub Releases Management cli
Go
22
star
12

wave

The wave is a tiny WAV sound module
Nim
20
star
13

nmi

nmi display animations aimed to correct users who accidentally enter nmi instead of nim. nmi is heavily inspired by sl .
Nim
13
star
14

nimsh

nimsh is a simple implementation of a shell in pure Nim.
Nim
12
star
15

TKoolFacetileMaker2

RPGツクールVXACE・MV・MZの画像差分ファイル作成用GUIソフト
Kotlin
12
star
16

repo-template-nim

Nim project template.
Nim
10
star
17

nimothello

A teminal othello (reversi) in Nim.
Nim
10
star
18

nimlint-action

NIm lint GitHub Actions.
Shell
10
star
19

termnovel

A command that to read novel on terminal.
Nim
10
star
20

MVTextEditor

RPGツクールMVのテキスト編集ツール
Java
10
star
21

sayhissatsuwaza

コマンドラインだって必殺技を叫びたい
Nim
9
star
22

rena

rena is a tiny fire/directory renaming command.
Nim
8
star
23

filetype

Small and dependency free Nim package to infer file and MIME type checking the magic numbers signature.
Nim
8
star
24

build-rpm-action

build-rpm-action builds a simple rpm package.
Nim
8
star
25

envconfig

envconfig provides a function to get config objects from environment variables.
Nim
8
star
26

TKoolImageTileEditor

RPGツクールの顔差分ファイルを編集するソフト
Java
7
star
27

gsv

gsv transforms a multi-line CSV into one-line JSON to make it easier to grep.
Go
7
star
28

dotfiles

次郎の開発環境設定ファイル
Vim Script
7
star
29

meme

自作のCLIツールを命名するためのツール
Clojure
6
star
30

workspace

次郎の開発環境
Shell
6
star
31

TKoolCharacterAnimationSimulator

RPGツクールMVのキャラチップアニメーションのシミュレーションソフト。
Java
6
star
32

svgo

This is svgo, a small utility to create SVG objects.
Nim
6
star
33

align

Simple text align CLI
Go
6
star
34

alignment

alignment is a library to align strings.
Nim
5
star
35

xlsxlang

A tiny toy script programming language with Excel.
Go
5
star
36

yourutils

Tiny your cli utilities in pure Nim
Nim
5
star
37

eastasianwidth

Library for East Asian Width in pure Nim.
Nim
5
star
38

ponpe

アルファベットを結合してpͪoͣnͬpͣoͥnͭpͣa͡iͥnするコマンド
Go
4
star
39

pnm

Library for PNM in pure Nim.
Nim
4
star
40

maze

A library to generate maze in pure Nim.
Nim
4
star
41

markx

markx selects execution targets with editor and executes commands.
Nim
3
star
42

vhwatch

Simple watch CLI with monitoring multiple commands execution.
Go
3
star
43

joyn

joyn joins lines of two files with a common characters, field or regular expression.
Nim
3
star
44

eachdo

Nim
3
star
45

nimbot

Nim code execution bot
Nim
3
star
46

coc-radar

キャラクター保管所のクトゥルフの探索者の能力値をレーダーチャートで表示するWebサイト
JavaScript
3
star
47

tetris

Terminal Tetris
Go
2
star
48

mcp

mcp copies multiple files with editor. mcp is heavily inspired by itchyny/mmv.
Nim
2
star
49

scripts

自分用のスクリプト置き場。大多数はbashで書かれている
Shell
2
star
50

suln

suln is a CLI that prints surroundings of line number with grep.
Rust
2
star
51

morsed

Clojure
2
star
52

godot_practice

Godotの練習コード置き場
GDScript
2
star
53

edfsay

EDF! EDF!!
Shell
2
star
54

taishoku

コマンドで退職届を提出する
Go
2
star
55

muse

Nim
2
star
56

calendar-go

Go
2
star
57

nim_sdl2_samples

Nim
2
star
58

own-weather

Twitterの自身のユーザ名に天気を付与します。
JavaScript
2
star
59

MVSkillsEditor

RPGツクールMVのスキルデータベース編集用GUIソフト
Java
2
star
60

rect

Command to crop/paste rectangle text.
Nim
2
star
61

tinyutils

Minimum commands
Go
1
star
62

trans

行列データを入れ替えるだけのコマンド
Go
1
star
63

sekigae

席替えプログラム
Go
1
star
64

colc

CombinatorLogic文字列を計算するツール
Go
1
star
65

sqlfmt

Nim
1
star
66

ski

Library for calculation SKI Combinator in pure Nim.
Nim
1
star
67

jiro4989

1
star
68

dist-illust

配布用のイラスト管理・生成リポジトリ
Shell
1
star
69

jira_issue_url_generator

JIRAのissues作成用URLをGitHub Pagesでやる
TypeScript
1
star
70

lib-js

web制作の時に便利な関数まとめ
JavaScript
1
star
71

txtconv4mv

RPGツクールMV用のテキストファイル→イベント変換ツール
Nim
1
star
72

aws-lambda-slack-bot

Nim
1
star
73

edens

edensは任意の辞書で文字列をエンコード・デコードするコマンドです
Nim
1
star
74

dejo

dejo generates multiple language object definitions from json documents.
Nim
1
star
75

parseetcpasswd

Nim
1
star
76

bookmarkapp

Kubernetesの勉強がてらアプリを作ってみる
JavaScript
1
star
77

codepoint

codepoint prints codepoint of characters.
Nim
1
star
78

toilet

Docker image of toilet command
Dockerfile
1
star
79

note

📝 A note cli for you
Nim
1
star
80

jiro4989.github.io

次郎のホームページ。ただのリンク集。
1
star
81

text-proofreading

文章添削リポジトリ。ブログとかQiitaの文章を書くために
Shell
1
star
82

image

Nim
1
star
83

tdur

時刻と時刻の差を計算するコマンド
Go
1
star
84

MVVariablesSearcher

ツクールMVの変数検索・選択ツールです。
Java
1
star
85

daylog.vim

Vimで日報書くプラグイン
Vim Script
1
star
86

go-timer

CLI Timer in Golang
Go
1
star
87

gyaric

gyaric is a module to encode/decode text to unreadable gyaru’s text.
Nim
1
star
88

subnet

subnet prints subnet mask in human readable.
Nim
1
star
89

imgctl

複数の画像を一括操作するだけのツール
Go
1
star
90

textchat

textchat is a terminal chat cli.
Go
1
star
91

sekigae.nim

席替えプログラム
Nim
1
star
92

chof

Nim
1
star
93

yml2conf

A config file generator from YAML
Nim
1
star
94

clgrep

grep for changelog
Go
1
star
95

aws-cfn-templates

Cloud Formationテンプレート
Python
1
star
96

minesweeper

飽きた
Go
1
star
97

tkradar

ツクールMVの職業のデータからレーダーチャートSVGを生成するCLI
Go
1
star
98

gameoflife

Library for Game of Life in pure Nim.
Nim
1
star
99

operation-scripts

サーバ保守運用で使うシェルスクリプト
Shell
1
star
100

arth

平均値、中央値、パーセンタイル値をさっと計算するCLI
Go
1
star