asciinema / agg

asciinema gif generator
https://docs.asciinema.org/manual/agg/
Apache License 2.0
1.18k stars 43 forks source link

Generated gif is very blurry no matter the font size #60

Closed ahelwer closed 10 months ago

ahelwer commented 10 months ago

Describe the bug When I generate a gif it is very blurry. This is the case no matter how much I increase the font size.

To Reproduce Steps to reproduce the behavior:

  1. Run cargo install --git https://github.com/asciinema/agg
  2. Download this asciinema file: https://asciinema.org/a/620647
  3. Run agg 620649.cast output.gif
  4. Observe blurriness:

demo

Expected behavior I expected a gif to be generated with non-blurry text, similar to the demonstration examples in the README.

Versions:

Additional context Output of -v:

[INFO  agg] terminal size: 59x18
[INFO  agg] selected font families: ["DejaVu Sans Mono", "DejaVu Sans"]
[INFO  agg] selected theme: dracula
[INFO  agg] gif dimensions: 514x372
93 / 93 [=================================================================================================================================================] 100.00 % 203.99/s 
[INFO  agg] rendering finished in 0.45609793s
ahelwer commented 10 months ago

I also tried this on macOS with the same result.

ku1ik commented 10 months ago

agg's font renderer uses anti-aliasing, which makes text blurry at lower resolutions. Your output shows 514x372 image size for the default font size (14px).

Have you tried doubling the font size?

Here's what I did:

agg -v --font-size 28 https://asciinema.org/a/620647 out3.gif
[INFO  agg] terminal size: 59x18
[INFO  agg] selected font families: ["JetBrains Mono", "DejaVu Sans Mono", "Liberation Mono", "DejaVu Sans"]
[INFO  agg] selected theme: dracula
[INFO  agg] gif dimensions: 1025x745
93 / 93 [================================================================================] 100.00 % 70.50/s 
[INFO  agg] rendering finished in 1.3192732s

Resulting GIF:

out3

I agree it's not super-sharp at this font-size though.

The example in the README uses JetBrains Mono font, and, if I remember correctly, was generated with --font-size 28.

There are 2 frame renderers in agg: fontdue (default), and resvg.

I also tested with alternative resvg renderer, which renders each frame by first generating SVG and then rasterizing it:

agg -v --font-size 28 --renderer resvg https://asciinema.org/a/620647 out3.gif

The result is similar though (resvg renderer doesn't handle special symbols/icons well, ignore that):

out3-resvg

I believe what you observe in the README example is a result of bigger terminal size in the recording (wider, taller) combined with 28px font size. That GIF file is wider than the width of the README display (if you displayed it 1:1), so the browser scales it down to fit the container, making the font look sharper.

ahelwer commented 10 months ago

I think you're right that the sharpness I'm seeking is found with larger font/higher resolution along with the image being restricted to a smaller window. Thanks!