Shell: envíe texto a PNG conservando el color

Shell: envíe texto a PNG conservando el color

Me gusta poder guardar el resultado de un comando de Shell como una imagen PNG sin perder el formato. Algo así como tomar una captura de pantalla del resultado.

some-command-with-color | text-to-png a.png

Sé que este comando convierte texto a PNG, pero no conserva el color:

tldr -c tldr | convert -page  4000x4000 -font FreeMono -pointsize 20  -background white -trim +repage -bordercolor white  -border 15 text:- png:a.png

ingrese la descripción de la imagen aquí

Respuesta1

Un programa que hace eso esansilove. Ya está empaquetado para muchas distribuciones.

Por ejemplo:

$ ls --color > /tmp/output.ansi
$ ansilove -o /tmp/output.png /tmp/output.ansi

Respuesta2

Como alternativa aansilove, también hayansigo(hecho por las mismas personas pero mucho más simple) yAnsiToImgotextimg.

AnsiToImg

# installation
pip install ansitoimg

# from file to image
ansitoimg /tmp/dcd.log dcd.svg

# pipeline
ls --color=always /etc | ansitoimg ls.svg

# preserving color in pipeline
unbuffer grc ss -nlpt | ansitoimg ss.svg

# use theme and wide screen
dcd -d za.tryhackme.com -s 10.200.28.101 | ansitoimg -w -t /tmp/one-dark.yaml /tmp/dcd.png

textimg

# from file to image
cat /tmp/dcd.log| textimg -o out.png

# pipeline
ls --color=always /etc | textimg -o out.png

# preserving color in pipeline
unbuffer grc ss -nlpt | textimg -o out.png

# choose font (-f), emoji font (-e) and use emoji font (-i)
dcd -d za.tryhackme.com -s 10.200.28.101 | textimg -f /usr/share/fonts/TTF/Anonymous\ Pro.ttf -e /usr/share/fonts/joypixels/JoyPixels.ttf -i -o /tmp/out.png

información relacionada