Convert code snippets into images. Powered by shiki and takumi. Super fast π
Convert code snippets into images. Powered by shiki and takumi. Super fast π
undefinedExample:undefined
[!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);
langCode language. See shiki supported languages
themeRendering theme. See shiki supported theems.
styleAdditional container styles. See takumi stylesheets.
formatOutput format can be either png, webp, avif, or jpeg (default is webp).
qualityImage quality between 0 to 100 (jpeg format only)
fontFont 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 use the builtinGeist Monofont from Takumi.
[!TIP]
If a URL is passed, response will be cached in memory for the next renders.
fontRatioFont ratio used to compute the final font size. Default is 0.63.
widthRendering width. By default is computed as columns * fontSize * fontRatio.
[!NOTE]
Default font size is32and can be customized usingstyle.fontSize.
heightRendering height. By default is computed as lines * fontSize * lineHeight.
[!NOTE]
Default lineHeight is1.3and can be customized usingstyle.lineHeight.
Published under the MIT license.