셸: 색상을 유지하면서 텍스트를 PNG로 출력합니다.

셸: 색상을 유지하면서 텍스트를 PNG로 출력합니다.

나는 서식을 잃지 않고 쉘 명령의 출력을 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

대안으로안실러브, 또한 있습니다안시고(동일한 사람이 만들었지만 훨씬 간단함)AnsiToImg또는문자 메시지.

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

문자 메시지

# 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

관련 정보