
Flashot is the blazing-fast image generation tool for code snippets, designed for flawless experience and speed.
- π» Inline code support: Easily convert inline code snippets to images
- π URL support: Fetch code snippets directly from URLs
- π¨ Customizable styles: Choose from various options to match your style
- πΌοΈ High-quality output: Generates crisp and clear images which keep the original code's formatting intact
- β‘ Blazing fast: Optimized for speed, ensuring quick image generation
- π οΈ Easy to use: Easy to integrate into your projects with a simple API
- πͺ Multi-format support: Generate images in various formats (PNG, JPEG, WebP)
- π· TypeScript support: Fully typed for better developer experience
- π Extensive testing: Thoroughly tested with a comprehensive suite of unit tests
- π Easy integration: Simple API for seamless integration into your projects
- π¦ Lightweight: Minimal dependencies to keep your project lean
- π Line numbers: Support for displaying & customizing line numbers
- ποΈ Cache management: Efficiently handles caching for improved performance (render, tokens, sizes, fonts)
bun install flashot
npm install flashot
yarn add flashot
pnpm add flashot
import { writeFile } from "node:fs/promises";
import { codeToImg } from "flashot";
const buffer = await codeToImg('console.log("hello, world!");', {
/* add more options*/
});
await writeFile("output.webp", buffer);
import { writeFile } from "node:fs/promises";
import { urlToImg } from "flashot";
const buffer = await urlToImg(
"https://mdn.github.io/learning-area/javascript/oojs/json/superheroes.json",
{
/* add more options*/
format: OutputFormat.Png,
}
);
await writeFile("output.png", buffer);
Then you can use the buffer
to display the image or send it in a response.
const defaultOptions = {
lang: "ts", // default is javascript
theme: "ayu-dark", // default is github-dark
font: "https://fonts.bunny.net/ubuntu-sans-mono/files/ubuntu-sans-mono-latin-400-normal.woff2", // default is bunny.net/jetbrains-mono.
format: OutputFormat.Png, // default is OutputFormat.Webp (options: OutputFormat.Png, OutputFormat.Jpeg, OutputFormat.Webp)
quality: 100, // default is 100 (1-100), only applies to JPEG formats
width: 800, // default is system's width
height: 400, // default is system's height
bg: "transparent", // default is system's background
gap: 1, // gap between lines (default is 1)
style: {
borderRadius: 10, // default is 8
padding: 30, // default is 25
// ... more custom styles
},
lineNumbers: {
enabled: false,
startFrom: 1,
color: "#7b7f8b",
marginRight: 0,
},
};
Option | Description | Default |
---|---|---|
lang |
Code language (supported) | "js" |
theme |
Rendering theme (supported) | "github-dark" |
font |
Font for rendering (URL or ArrayBuffer) | Jetbrains Mono |
format |
Output image format (OutputFormat.Png , OutputFormat.Jpeg , OutputFormat.Webp ) |
OutputFormat.Webp |
quality |
Image quality (1-100) for JPEG formats | 100 |
width |
Image width | System default |
height |
Image height | System default |
bg |
Background color | Theme's background |
gap |
Gap between lines | 1 |
style |
Additional container styles (docs) | { borderRadius: 8, padding: 25 } |
lineNumbers |
Line number styles | { enabled: false, color: '#7b7f8b', marginRight: 0 } |
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---|---|---|---|---|---|
All files | 99.17 | 81.25 | 100 | 99.17 | |
core.ts | 100 | 100 | 100 | 100 | |
index.ts | 100 | 100 | 100 | 100 | |
shared.ts | 100 | 100 | 100 | 100 | |
utils.ts | 98.36 | 78.57 | 100 | 98.36 | 67 |
No | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples |
---|---|---|---|---|---|---|
0 | small code (10 lines) | 201215722 Β± 4.80% | 186069100 Β± 8369100 | 5 Β± 3.54% | 5 Β± 0 | 64 |
1 | medium code (100 lines) | 349906927 Β± 6.43% | 317186800 Β± 6326800 | 3 Β± 3.95% | 3 Β± 0 | 64 |
2 | large code (1000 lines) | 1726190939 Β± 0.46% | 1715535300 Β± 13138650 | 1 Β± 0.45% | 1 Β± 0 | 64 |
- β‘ Bun - Fast all-in-one JavaScript runtime and toolkit
- ποΈ TypeScript - Type-safe development with strict mode enabled
- π¦ Vite - Lightning-fast build tool with optimized bundling
- πͺ Tsdown - A powerful tool for TypeScript package
- π§ͺ Vitest - Blazing fast unit testing & interactive test UI framework
- π¨ Shiki and Takumi - Render container highlight
- π Biome - Fast formatter and linter for consistent code style
- π Dual Module Support - ESM and CommonJS output with proper type definitions
- π₯ ESLint - Advanced linting with TypeScript and SonarJS rules
- π§© Lefthook and Commitlint - Automated Git hooks for linting and formatting
- π οΈ Tinybench - A tiny benchmarking library for measuring performance
Contributions are welcome! This starter kit uses:
- Automated code formatting and linting
- Comprehensive test coverage requirements
Please ensure all tests pass and code quality checks succeed before submitting a PR.
Check CONTRIBUTING.md for more information.
Head over to the discussions to share your ideas.