Convert Color Text to Images in Bash
The textmg
is a cool little CLI tool written by jiro4989 – a systems engineer from Japan – that allows you to convert the color output in a terminal window to an image file. I find this very useful when sharing code snippets on social media and when writing documentation.
Installation
Debian-based distros
u="https://github.com/jiro4989/textimg/releases"
v="$(curl -s0 -k "${u}" | grep -oP "(?<=/v)[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}(?=/)" | sort -Vu | tail -1)"
wget "${u}/download/v${v}/textimg_${v}_amd64.deb"
sudo dpkg -i ./textimg_${v}_amd64.deb
RHEL-compatible distros
u="https://github.com/jiro4989/textimg/releases"
v="$(curl -s0 -k "${u}" | grep -oP "(?<=/v)[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}(?=/)" | sort -Vu | tail -1)"
sudo yum install "${u}/download/v${v}/textimg-${v}-1.el7.x86_64.rpm"
Examples
Colorize output of top
using lolcat
and save it as a PNG file:
top -b -n 1 | lolcat | textimg -o /var/tmp/test_${RANDOM}.png
Save output of screenfetch
(see it here) as a graphic file:
screenfetch | textimg -o /var/tmp/test_${RANDOM}.png
Convert a shell script with syntax highlighting to PNG using the syntax
function (you can find it here):
syntax atq_jobs.sh | textimg -o /var/tmp/test_${RANDOM}.png
Using the fact
function (you can find it here), generate fifty PNG images:
for i in `seq 1 50`; do fact | textimg -o /var/tmp/test_${RANDOM}.png; done