Shell: Text unter Beibehaltung der Farbe als PNG ausgeben

Shell: Text unter Beibehaltung der Farbe als PNG ausgeben

Ich möchte die Ausgabe eines Shell-Befehls gerne als PNG-Bild speichern können, ohne dass die Formatierung verloren geht. Das ist so, als würde man einen Screenshot der Ausgabe machen.

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

Ich weiß, dass dieser Befehl Text in PNG konvertiert, aber die Farbe bleibt nicht erhalten:

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

Bildbeschreibung hier eingeben

Antwort1

Ein Programm, das dies tut, istansilove. Es ist bereits für viele Distributionen gepackt.

Zum Beispiel:

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

Antwort2

Als Alternative zuAbonnieren, es gibt auchansigo(von den gleichen Leuten gemacht, aber viel einfacher) undAnsiToImgoderTextbild.

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

Textbild

# 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

verwandte Informationen