Skip to content

Convert code snippets into images. Powered by shiki and takumi. Super fast πŸš€

License

Notifications You must be signed in to change notification settings

jd-solanki/shiki-image

Β 
Β 

Repository files navigation

shiki-image

npm version npm downloads

Convert code snippets into images. Powered by shiki and takumi. Super fast πŸš€

Example:

Example output

Note

This was a quick experimental project. Contributors needed!

Usage

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);

Options

lang

Code language. See shiki supported languages

theme

Rendering theme. See shiki supported theems.

style

Additional container styles. See takumi stylesheets.

format

Output format can be either png, webp or jpeg (default is webp).

quality

Image quality between 0 to 100 (jpeg format only)

font

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.

fontRatio

Font ratio used to compute the final font size. Default is 0.63.

width

Rendering width. By default is computed as columns * fontSize * fontRatio.

Note

Default font size is 18 and can be customized using style.fontSize.

height

Rendering height. By default is computed as lines * fontSize * lineHeight.

Note

Default lineHeight is 1.3 and can be customized using style.lineHeight.

Development

local development
  • Clone this repository
  • Install latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

Showcase

  • Alekhya: Code image generator with API support

License

Published under the MIT license.

About

Convert code snippets into images. Powered by shiki and takumi. Super fast πŸš€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.0%
  • JavaScript 5.0%