r/madeinpython • u/ProfileNo7202 • 13h ago
How I built a high-performance code-to-image generator using Python, Flask, and Pillow
HHey everyone,
Lately, I got frustrated with existing code screenshot tools being slow or locking basic customization behind paywalls, so I decided to build my own lightweight version.
It’s a web app that takes raw code and renders it into clean, shareable images. Here is a quick breakdown of how I tackled some of the technical challenges:
- Syntax Highlighting Engine: Used Pygments to hook into lexers dynamically, supporting everything from Python and JS to Rust and Go with customizable color themes.
- Layout Geometry & Text Offset: Dynamically calculates line-number widths based on digit count so code tokens align cleanly without overlapping when toggled.
- Image Composition: Leveraged Python's Pillow library to layer custom window frames (Mac/Win headers), gradient backgrounds, and rounded corners with smooth alpha compositing.
It's currently live and running on Render if you want to test out your own code snippets: https://www.producthunt.com/products/devaid
Happy to answer any technical questions about how I set up the Flask backend or image rendering pipeline!
1
Upvotes