finds.dev← search

// the find

akira-cn/code-to-image

★ 275 · JavaScript · MIT · updated Mar 2018

Convert blocks of code to a highlighted jpeg base64 image.

A browser-based tool that renders syntax-highlighted code into a JPEG image using html2canvas, so you can paste code snippets into platforms that strip code formatting. It wraps Google's code-prettify for highlighting and html2canvas for the DOM-to-image conversion. Useful for sharing code on Weibo, WeChat, or any platform that mangles preformatted text.

The core idea is genuinely practical — html2canvas lets you capture styled DOM as an image without a server round-trip, so there's no upload or backend needed. Bundling 40+ language grammars via code-prettify extensions covers most real use cases. The build pipeline is minimal (Gulp + npm), so forking and customizing the theme or layout is straightforward. JPEG output keeps file sizes small enough for social sharing.

Last commit was March 2018 — html2canvas has had multiple major releases since then, and this is pinned to an old bundled copy with no upgrade path. JPEG is the wrong format for text: the lossy compression introduces artifacts on high-contrast edges like code characters, making some output genuinely hard to read at low quality settings. There's no API or CLI — it's purely a browser UI, so you can't integrate it into a CI pipeline or automate screenshot generation. The demo URLs point to domains that are almost certainly dead, so you can't evaluate it without running it locally.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →