On occasion I find myself struggling posting code on discussion forums that don’t handle code formatting all that well. What would’ve helped is some quick and easy way to convert code to an image file with syntax highlighting. And so here it is.

The first step is to install some prerequisites.

In the script below you can modify a few things: font face, font size, and image size. You can list the appropriate fonts available on your system like so:

The script itself needs to be executed this way:

You can install the script from my GitHub repo like so:

And the script itself is below.
It’s a very simplistic version that begs for a rewrite. Alas, this was all the time I could spare. By all means, feel free to make improvements. Here are some output examples: