Shell:將文字輸出為 PNG,同時保留顏色

Shell:將文字輸出為 PNG,同時保留顏色

我希望能夠將 shell 命令的輸出儲存為 PNG 映像,而不會遺失格式。有點像輸出的螢幕截圖。

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

我知道這個命令將文字轉換為 PNG,但它不保留顏色:

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

在此輸入影像描述

答案1

執行此操作的程序是ansilove。它已經針對許多發行版進行了打包。

例如:

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

答案2

作為替代方案安西洛夫,還有安西戈(由同一個人製作,但簡單得多)和安西托影像或者簡訊

安西托影像

# 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

簡訊

# 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

相關內容