Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18995

Pygments and ImageFormatter: set output to 80 columns

$
0
0

The ImageFormatter always creates a PNG output which width depends on the line length.

For example, this PNG is 192 pixels wide:

short

and this is 384:

long

Is there a setting in Pygments to emulate a 80 column output, so all images will have the same width?

This is the code I used to produce the examples:

#!/usr/bin/python3from pygments import highlightfrom pygments import lexersfrom pygments.formatters.img import ImageFormatterfrom pygments.styles import get_style_by_name, get_all_styleslexer = lexers.get_lexer_by_name('C')source_short = 'printf("%d\\n", i);'source_long = 'printf("variable i is equal to %d.\\n", i);'formatter = ImageFormatter(full = True, style = get_style_by_name('vim'))open('short.png', 'wb').write(highlight(source_short, lexer, formatter))formatter = ImageFormatter(full = True, style = get_style_by_name('vim'))open('long.png', 'wb').write(highlight(source_long, lexer, formatter))

Viewing all articles
Browse latest Browse all 18995

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>