### Start Satori Development Mode
Source: https://github.com/vercel/satori/blob/main/CONTRIBUTING.md
Run this command in the root directory to start the development mode for Satori. Recommended to use with the playground.
```bash
pnpm dev
```
--------------------------------
### Install Dependencies with pnpm
Source: https://github.com/vercel/satori/blob/main/CONTRIBUTING.md
Use this command to install project dependencies when setting up local development.
```bash
pnpm install
```
--------------------------------
### Run Playground and Satori Locally
Source: https://github.com/vercel/satori/blob/main/CONTRIBUTING.md
Start the Satori playground and the Satori development server simultaneously for local testing.
```bash
pnpm dev:playground
```
--------------------------------
### Live-Watch Satori Tests with Vitest
Source: https://github.com/vercel/satori/blob/main/CONTRIBUTING.md
Execute this command to start Vitest in live-watch mode, running tests and updating snapshots as changes are made.
```bash
pnpm dev:test
```
--------------------------------
### Satori SVG Output Example
Source: https://github.com/vercel/satori/blob/main/README.md
This is an example of the SVG string output generated by Satori after processing JSX and options.
```js
''
```
--------------------------------
### Initialize Satori Standalone Build with WASM
Source: https://github.com/vercel/satori/blob/main/README.md
For the standalone build, manually load the `yoga.wasm` binary using `fetch` or `fs.readFile` and initialize Satori with it before use.
```javascript
import satori, { init } from 'satori/standalone'
const res = await fetch('https://unpkg.com/satori/yoga.wasm')
const yogaWasm = await res.arrayBuffer()
await init(yogaWasm)
// Now you can use satori as usual
const svg = await satori(...)
```
--------------------------------
### Advanced Satori Configuration with SatoriOptions
Source: https://context7.com/vercel/satori/llms.txt
Illustrates advanced configuration using the SatoriOptions object, including custom fonts, Tailwind CSS integration, dynamic asset loading, and debugging options. Ensure font data is fetched or loaded.
```typescript
import satori from 'satori'
import type { SatoriOptions, Font } from 'satori'
const fonts: Font[] = [
{
name: 'Inter',
data: await fetch('https://example.com/Inter-Regular.woff').then(r => r.arrayBuffer()),
weight: 400,
style: 'normal',
},
{
name: 'Inter',
data: await fetch('https://example.com/Inter-Bold.woff').then(r => r.arrayBuffer()),
weight: 700,
style: 'normal',
},
]
const options: SatoriOptions = {
width: 800, // Required: output width in pixels
height: 400, // Required: output height in pixels
fonts: fonts, // Required: array of font configurations
embedFont: true, // Optional: embed fonts as paths (default: true)
debug: false, // Optional: draw bounding boxes for debugging
pointScaleFactor: 2, // Optional: pixel grid rounding for high-DPI
tailwindConfig: { // Optional: custom Tailwind configuration
theme: {
extend: {
colors: { brand: '#0070f3' }
}
}
},
graphemeImages: { // Optional: custom images for specific characters
'π': 'https://example.com/rocket.svg',
},
loadAdditionalAsset: async (languageCode, segment) => {
// Optional: dynamically load fonts/emojis for missing characters
if (languageCode === 'emoji') {
return `https://cdn.example.com/emoji/${segment}.svg`
}
// Return font data for missing language fonts
return fetch(`https://example.com/fonts/${languageCode}.woff`)
.then(r => r.arrayBuffer())
.then(data => ({ name: 'Fallback', data, weight: 400, style: 'normal' }))
},
onNodeDetected: (node) => {
// Optional: callback for each detected layout node
console.log('Node:', node.type, node.left, node.top, node.width, node.height)
}
}
const svg = await satori(
Advanced Configuration Example
,
options
)
```
--------------------------------
### Basic Satori Usage with JSX
Source: https://github.com/vercel/satori/blob/main/README.md
Demonstrates the fundamental way to use Satori with JSX to render a simple HTML element into an SVG. Ensure font data is provided if needed.
```jsx
import satori from 'satori'
const svg = await satori(
hello, world
,
{
width: 600,
height: 400,
fonts: [
{
name: 'Roboto',
// Use `fs` (Node.js only) or `fetch` to read the font as Buffer/ArrayBuffer and provide `data` here.
data: robotoArrayBuffer,
weight: 400,
style: 'normal',
},
],
},
)
```
--------------------------------
### Run Satori Tests with Vitest
Source: https://github.com/vercel/satori/blob/main/CONTRIBUTING.md
Use this command to run all Satori tests once using Vitest.
```bash
pnpm test
```
--------------------------------
### Standalone Build with External WASM for Restricted Environments
Source: https://context7.com/vercel/satori/llms.txt
Utilize the standalone Satori build and manually load the Yoga WASM binary for environments with WASM loading restrictions, such as Cloudflare Workers. Initialize Satori with the fetched WASM binary before use.
```typescript
import satori, { init } from 'satori/standalone'
// Load Yoga WASM manually
const yogaWasm = await fetch('https://unpkg.com/satori/yoga.wasm')
.then(res => res.arrayBuffer())
// Initialize Satori with the WASM binary
await init(yogaWasm)
// Now use satori as normal
const svg = await satori(
Running in Cloudflare Workers!
,
{
width: 800,
height: 400,
fonts: [{
name: 'Inter',
data: await fetch('https://example.com/Inter.woff').then(r => r.arrayBuffer()),
weight: 400,
style: 'normal',
}],
}
)
```
--------------------------------
### Embedding Images with Satori
Source: https://github.com/vercel/satori/blob/main/README.md
Illustrates how to embed images using the `` tag in Satori. Specifying width and height is recommended. Supports base64 encoded image data for direct rendering.
```jsx
await satori(
,
options
)
```
```jsx
await satori(
,
// Or src={arrayBuffer}, src={buffer}
options
)
```
--------------------------------
### Basic JSX to SVG Conversion with Satori
Source: https://context7.com/vercel/satori/llms.txt
Demonstrates the fundamental usage of the satori() function to convert a simple JSX structure with inline styles into an SVG string. Requires font data to be loaded.
```typescript
import satori from 'satori'
import { readFile } from 'fs/promises'
// Load font data (required for text rendering)
const robotoData = await readFile('./Roboto-Regular.ttf')
// Basic usage - render JSX to SVG
const svg = await satori(
Hello, World!
,
{
width: 1200,
height: 630,
fonts: [
{
name: 'Roboto',
data: robotoData,
weight: 400,
style: 'normal',
},
],
}
)
// Result: ''
console.log(svg)
```
--------------------------------
### Configure Fonts for Text Rendering
Source: https://context7.com/vercel/satori/llms.txt
Load and configure multiple font files with specific weights, styles, and language overrides for accurate text rendering across different locales. Ensure fallback font order is considered.
```typescript
import satori from 'satori'
import { readFile } from 'fs/promises'
// Load multiple font weights and styles
const interRegular = await readFile('./Inter-Regular.ttf')
const interBold = await readFile('./Inter-Bold.ttf')
const interItalic = await readFile('./Inter-Italic.ttf')
const notoSansJP = await readFile('./NotoSansJP-Regular.otf')
const notoSansSC = await readFile('./NotoSansSC-Regular.otf')
const svg = await satori(
,
options
)
```
```
--------------------------------
### Enable Debug Mode in Satori
Source: https://github.com/vercel/satori/blob/main/README.md
Pass `debug: true` as an option to draw bounding boxes around elements for debugging purposes.
```jsx
const svg = await satori(
hello, world
,
{
...,
debug: true,
},
)
```
--------------------------------
### Render SVG with Comprehensive CSS Support
Source: https://context7.com/vercel/satori/llms.txt
Use Satori to generate SVGs with support for flexbox, borders, shadows, transforms, text styling, and CSS variables. Ensure fonts are loaded for text rendering.
```typescript
import satori from 'satori'
const svg = await satori(
{/* Flexbox layout */}
{/* Borders and shadows */}
Card with border and shadow
{/* Transforms */}
{/* Text styling */}
Styled Text
{/* CSS Variables */}
{/* Text overflow and line clamping */}
This is a long text that will be clamped to two lines with an ellipsis at the end...
,
{ width: 500, height: 600, fonts }
)
```
--------------------------------
### Use Built-in JSX Runtime for Type-Safe Components
Source: https://context7.com/vercel/satori/llms.txt
Enable Satori's experimental JSX runtime with the `@jsxImportSource` pragma to use type-safe functional components without React. This allows for defining reusable UI elements with Satori-supported props.
```tsx
/** @jsxRuntime automatic */
/** @jsxImportSource satori/jsx */
import satori from 'satori'
import { createElement, Fragment } from 'satori/jsx'
import type { FC, JSXNode } from 'satori/jsx'
// Define typed functional components
interface CardProps {
title: string
description: string
children?: JSXNode
}
const Card: FC = ({ title, description, children }) => (
{title}
{description}
{children}
)
// Use with Satori
const svg = await satori(
Additional content,
{ width: 400, height: 200, fonts }
)
// Or use createElement directly without JSX
const element = createElement('div', { style: { color: 'red' } }, 'Hello')
const svg2 = await satori(element, { width: 100, height: 100, fonts })
```
--------------------------------
### Load Fonts and Emojis Dynamically
Source: https://context7.com/vercel/satori/llms.txt
Handles emoji rendering with Twemoji and loads language-specific fonts dynamically. Ensure necessary fonts are available or provide fallback URLs.
```typescript
import satori from 'satori'
const svg = await satori(
Use familiar Tailwind classes for rapid development
Primary Button
Secondary Button
,
{
width: 800,
height: 400,
fonts,
tailwindConfig,
}
)
```
--------------------------------
### Dynamically Load Emojis and Fonts
Source: https://github.com/vercel/satori/blob/main/README.md
Implement `loadAdditionalAsset` to dynamically load missing emoji images or fonts during text rendering. The function receives the code and segment to render.
```typescript
await satori(
π δ½ ε₯½
,
{
// `code` will be the detected language code, `emoji` if it's an Emoji, or `unknown` if not able to tell.
// `segment` will be the content to render.
loadAdditionalAsset: async (code: string, segment: string) => {
if (code === 'emoji') {
// if segment is an emoji
return `data:image/svg+xml;base64,...`
}
// if segment is normal text
return loadFontFromSystem(code)
}
}
)
```
--------------------------------
### satori() - Convert JSX to SVG
Source: https://context7.com/vercel/satori/llms.txt
The core function of the Satori library. It takes a React-like element (JSX) and an options object to render an SVG string. This is the primary method for generating SVGs.
```APIDOC
## satori() - Convert JSX to SVG
### Description
The main function that converts JSX elements into SVG strings. It accepts a React-like element and options object specifying dimensions, fonts, and rendering preferences.
### Method
`satori()`
### Parameters
#### Request Body
- **element** (ReactElement) - Required - The JSX element to convert to SVG.
- **options** (SatoriOptions) - Required - Configuration object for rendering.
### Request Example
```typescript
import satori from 'satori'
import { readFile } from 'fs/promises'
const robotoData = await readFile('./Roboto-Regular.ttf')
const svg = await satori(
Hello, World!
,
{
width: 1200,
height: 630,
fonts: [
{
name: 'Roboto',
data: robotoData,
weight: 400,
style: 'normal',
},
],
}
)
console.log(svg)
```
### Response
#### Success Response (200)
- **svgString** (string) - The generated SVG string.
#### Response Example
```
''
```
```
--------------------------------
### Render Custom Emojis with graphemeImages
Source: https://github.com/vercel/satori/blob/main/README.md
Use the `graphemeImages` option to map specific graphemes to image sources for custom emoji rendering. Images are resized to the font size.
```jsx
await satori(
Next.js is π€―!
,
{
...
graphemeImages: {
'π€―': 'https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/1f92f.svg',
},
}
)
```
--------------------------------
### Control Pixel Grid Rounding with pointScaleFactor
Source: https://github.com/vercel/satori/blob/main/README.md
Use `pointScaleFactor` to adjust how layout values are rounded to the pixel grid, enhancing rendering precision on high-DPI displays. This option is passed directly to Yoga.
```jsx
const svg = await satori(
hello, world
,
{
...,
pointScaleFactor: 2,
},
)
```
--------------------------------
### Embed Images and Background Images
Source: https://context7.com/vercel/satori/llms.txt
Embeds images using `` tags or CSS `background-image`. Supports URLs, data URIs, and ArrayBuffers. Gradient backgrounds are also supported.
```typescript
import satori from 'satori'
const svg = await satori(
{/* Image from URL */}
{/* Image from base64 data URI */}
{/* Background image with gradient overlay */}
,
{ width: 400, height: 500, fonts }
)
```
--------------------------------
### Specify Locale for Text Rendering
Source: https://github.com/vercel/satori/blob/main/README.md
Use the `lang` attribute to specify the locale for rendering text, which can affect how characters are displayed.
```jsx
await satori(
ιͺ¨
)
```
--------------------------------
### Specify Fonts for Text Rendering
Source: https://github.com/vercel/satori/blob/main/README.md
Pass font data as ArrayBuffer (web) or Buffer (Node.js) when specifying fonts for text rendering. Multiple fonts can be used with `fontFamily`.
```jsx
await satori(
Hello
,
{
width: 600,
height: 400,
fonts: [
{
name: 'Inter',
data: inter,
weight: 400,
style: 'normal',
},
{
name: 'Inter',
data: interBold,
weight: 700,
style: 'normal',
},
],
}
)
```
--------------------------------
### Locale-Aware Text Rendering in SVG
Source: https://context7.com/vercel/satori/llms.txt
Specify the `lang` attribute on elements to ensure correct character rendering for different locales, such as CJK scripts. Ensure corresponding fonts are provided in the options.
```typescript
import satori from 'satori'
// The character ιͺ¨ renders differently in Chinese vs Japanese
const svg = await satori(
{/* Default rendering */}
ιͺ¨ (default)
{/* Japanese rendering */}
ιͺ¨ (Japanese)
{/* Simplified Chinese rendering */}
ιͺ¨ (Chinese)
{/* Mixed content with explicit locale sections */}
,
{
width: 400,
height: 400,
fonts: [
{ name: 'Inter', data: interFont, weight: 400, style: 'normal' },
{ name: 'Noto Sans JP', data: notoJP, weight: 400, style: 'normal', lang: 'ja-JP' },
{ name: 'Noto Sans SC', data: notoSC, weight: 400, style: 'normal', lang: 'zh-CN' },
{ name: 'Noto Sans KR', data: notoKR, weight: 400, style: 'normal', lang: 'ko-KR' },
],
}
)
```
--------------------------------
### Disable Font Embedding in Satori
Source: https://github.com/vercel/satori/blob/main/README.md
Set `embedFont` to `false` to prevent Satori from inlining font path data, causing it to use `` elements instead of ``.
```jsx
const svg = await satori(
hello, world
,
{
...,
embedFont: false,
},
)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.