jiro4989 / textimg

Command to convert from color text (ANSI or 256) to image.
MIT License
221 stars 16 forks source link

Text not converting to image correctly within docker #206

Closed dtbaker closed 1 year ago

dtbaker commented 1 year ago

Describe the bug

It seems some characters are missing during the conversion.

To Reproduce

Build docker image locally on Raspberry Pi:

git clone https://github.com/jiro4989/textimg.git
cd textimg/
docker build . -t textimg

Install tmux and bpytop tools

sudo apt install tmux bpytop

Capture bpytop output into bpytop.txt file:

tmux new -dstelemetry 'bpytop'
tmux capture-pane -e -J -p -t telemetry > bpytop.txt
tmux kill-session

Use docker to convert output to image:

docker run -v $(pwd):/images --entrypoint "/bin/sh" -it textimg
# cat images/bpytop.txt | /usr/local/bin/textimg -o images/bpytop.jpg

Screenshots or Logs

image

Environment (please complete the following information)

Additional context

$ cat bpytop.txt 
┌─┤¹cpu├──┤Menu├┤mode:full├────────┤12:09:30├─────────────────────┤+ 2000ms -├─┐
│                                    ┌──────────────────────────────┤600 Mhz├┐ │
│                                    │CPU ■■■■■■■■■■■■■■■■■■   0% ⣶⣶⣶⣶⣶  58°C│ │
│       ⡀      ⢠⡀  ⡀                 │C1  ⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀  0%│C3  ⡀⡀⣀⡀⣀⡀⣀⡀⣀⡀⣀  1%│ │
│       ⠁      ⠘⠁  ⠁                 │C2  ⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀  0%│C4  ⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀  0%│ │
│                                    │                    LAV: 0.11 0.22 0.3 │ │
│ up 0:40                            └───────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────┘
┌─┤²mem├┤graph├───┬─┤dis┤io├┤swap├─┐┌─┤⁴proc├┤filter├─────┤tree├┤< cpu lazy >├─┐
│ Total: 7.62 GiB ├──root───14.3─G─┤│   Pid: Program:         MemB       Cpu% ↑│
│ U ⣀⣀⣀⣀⣀⣀  402 M │ U ■■■■■ 4.03 G ││   2815 python3           34M ⣀⣀⣀⣀⣀  0.8 █│
│ A ⣿⣿⣿⣿⣿⣿ 7.23 G ├──swap───99.9─M─┤│    669 dockerd           91M ⡀⡀⡀⡀⡀  0.0  │
│ C ⣤⣤⣤⣤⣤⣤ 2.02 G │ U ■■■■■   0 By ││    582 kworker/u9:2-brc   0B ⡀⡀⡀⡀⡀  0.0  │
│ F ⣶⣶⣶⣶⣶⣶ 5.28 G ├──boot────254─M─┤│   2814 tmux: server       3M ⡀⡀⡀⡀⡀  0.0  │
├─────────────────┤ IO ⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀  ││      1 systemd           10M ⡀⡀⡀⡀⡀  0.0  │
│                 │ U ■■■■■ 30.5 M ││    531 containerd        40M ⡀⡀⡀⡀⡀  0.0  │
│                 │                ││    848 node              75M ⡀⡀⡀⡀⡀  0.0  │
└─────────────────┴────────────────┘│    671 node              79M ⡀⡀⡀⡀⡀  0.0  │
┌─┤³net├─┤auto├┤zero├┤<b wlan0 n>├─┐│    170 systemd-udevd      6M ⡀⡀⡀⡀⡀  0.0  │
│10K           ┌─┤Download├──────┐ ││    900 sshd               4M ⡀⡀⡀⡀⡀  0.1  │
│      ⢀       │▼ 293 Byte/s     │ ││    137 systemd-journald  17M ⡀⡀⡀⡀⡀  0.0  │
│           ⠈⠈⠁│▲ 398 Byte/s     │ ││    881 systemd            8M ⡀⡀⡀⡀⡀  0.0  │
│10K           └─┤Upload├────────┘ ││     70 kworker/0:1H-mmc   0B ⡀⡀⡀⡀⡀  0.0 ↓│
└──────────────────────────────────┘└─┤↑ select ↓├┤info ↲├┤Terminate├──┤0/150├─

Attached:

bpytop.txt

dtbaker commented 1 year ago

Hello,

If I add this to the Dockerfile and re-built, the output image gets a bit nicer:

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

bpytop3

but still missing a few characters

jiro4989 commented 1 year ago

The textimg Dockerfile uses MyricaM as the font. https://github.com/jiro4989/textimg/blob/32e541eaf37f472bb1342454fd2f383c6e066d08/Dockerfile#L31

Maybe, the character is missing because the font file does not contain that character. Please add another fonts and overwrite the environment variable TEXTIMG_FONT_FILE.

dtbaker commented 1 year ago

Thank you for the suggestion.

I tried: DejaVuSansMono.ttf bpytop-defavu

Then NotoMono-Regular.ttf

bpytop-notomono

And NotoSansCJK-Regular.ttc

bpytop-notosans

And also Hack-Regular.ttf

bpytop-hack

Does the attached file work with any font you have by chance? bpytop.txt

Have you come across any other similar tools to this that I can try as well to see if they have the same problem?

Thank you very much.

jiro4989 commented 1 year ago

Does the attached file work with any font you have by chance?

I tried it, but the characters were missing.

Have you come across any other similar tools to this that I can try as well to see if they have the same problem?

I have never tried other tools. ImageMagick will be a similar tool.

jiro4989 commented 1 year ago

The missing characters (⢠⡀) will be Braille. For example, it will be drawn when I use a font that contains only Braille.

a

So this is a font issue.