Convert code snippets into images. Powered by shiki and takumi. Super fast π
Example:
Note
This was a quick experimental project. Contributors needed!
import { writeFile } from "node:fs/promises";
import { codeToImage } from "shiki-image";
const buffer = await codeToImage('console.log("hello, world!");', {
lang: "js",
theme: "github-dark",
format: "webp",
});
await writeFile("image.webp", buffer);Code language. See shiki supported languages
Rendering theme. See shiki supported theems.
Additional container styles. See takumi stylesheets.
Output format can be either png, webp or jpeg (default is webp).
Image quality between 0 to 100 (jpeg format only)
Font used to render the code. Can be either a string (remote URL to fetch) or an ArrayBuffer.
Note
If no font is specified, it will be automatically downloaded from bunny.net/jetbrains-mono.
Tip
If a URL is passed, response will be cached in memory for the next renders.
Font ratio used to compute the final font size. Default is 0.63.
Rendering width. By default is computed as columns * fontSize * fontRatio.
Note
Default font size is 18 and can be customized using style.fontSize.
Rendering height. By default is computed as lines * fontSize * lineHeight.
Note
Default lineHeight is 1.3 and can be customized using style.lineHeight.
local development
- Alekhya: Code image generator with API support
Published under the MIT license.