Generate images of your code with this open source server
Many developers are familiar with the likes of Carbon and Codeimg, which allow you to generate images of your code. They are extremely useful projects, but they are also closed source, don’t have APIs, and are not self-hostable. Inkify is an open source alternative that aims to solve these problems.
Inkify is written in Rust and makes use of a couple of other open source projects, including Silicon for rendering the code images, guesslang for detecting the programming language, and Actix Web for the server. Without these projects, Inkify would not be possible. Silicon is really the backbone and inspiration for the whole project, but since it’s mostly made to be a CLI tool it took some work to make it into a server.
Inkify has a very simple to use JSON based API, which is entirely documented with a GET request to the server root. You can see it yourself here, where I host the official instance. The most important route is
/generate, which takes a JSON body and returns a PNG image, though there are several other routes available including
/detect which does some language detection on the provided code.
I host pretty much everything I build with Docker, and Inkify is no exception. As such there is a ready-to-go Docker container available at https://hub.docker.com/r/watzon/inkify. You can also, of course, build it youself with the provided Dockerfile; be warned, the build process takes a while as it has to compile Tensorflow, download fonts, and build the Rust project.
Want to give Inkify a try without writing your own code? Here’s a simple component that make use of the Inkify API:
Inkify was inspired by my wanting to generate open graph images for my pastebin, paste69, and I’m very happy with how it turned out. It’s a simple project, but it’s also very useful and I hope others find it useful as well. Be sure to give the project a star on GitHub if you like it, and feel free to open an issue if you have any questions or suggestions.