Reading through Pygments' formatters doc (https://pygments.org/docs/formatters/), I cannot find how to wrap long lines of code when using the ImageFormatter in order to export my highlighted code to a png image.
Here's my code:
from pygments.lexers import PythonLexer
from pygments.formatters import ImageFormatter
from pygments import highlight
code = 'print("Reading through Pygments\' formatters doc (https://pygments.org/docs/formatters/), I cannot find how to wrap code when using the ImageFormatter in order to export my highlighted code to a png image (i.e. let\'s say I want my image to be 600px, or 300 characters at font size, wide). It seems like wrapping is essential when exporting to an image, is the option missing from Pygments at this moment?")'
formatter = ImageFormatter()
with open("highlighted1.png", "wb") as f:
f.write(highlight(code, PythonLexer(), formatter))
Which produces this image which (unusable for many applications):

It seems like wrapping is essential when exporting to an image, is the option missing from Pygments at this moment?