MCPcopy
hub / github.com/vercel/satori

github.com/vercel/satori @0.27.2 sqlite

repository ↗ · DeepWiki ↗ · release 0.27.2 ↗
316 symbols 898 edges 113 files 9 documented · 3%
README

Satori

Satori: Enlightened library to convert HTML and CSS to SVG.

Note

To use Satori in your project to generate PNG images like Open Graph images and social cards, check out our announcement and Vercel’s Open Graph Image Generation →

To use it in Next.js, take a look at the Next.js Open Graph Image Generation template →

Overview

Satori supports the JSX syntax, which makes it very straightforward to use. Here’s an overview of the basic usage:

// api.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',
      },
    ],
  },
)

Satori will render the element into a 600×400 SVG, and return the SVG string:

'<svg ...><path d="..." fill="black"></path></svg>'

Under the hood, it handles layout calculation, font, typography and more, to generate a SVG that matches the exact same HTML and CSS in a browser.

Documentation

JSX

Satori only accepts JSX elements that are pure and stateless. You can use a subset of HTML elements (see section below), or custom React components, but React APIs such as useState, useEffect, dangerouslySetInnerHTML are not supported.

Experimental: builtin JSX support

Satori has an experimental JSX runtime that you can use without having to install React. You can enable it on a per-file basis with @jsxImportSource pragmas. In the future, it will autocomplete only the subset of HTML elements and CSS properties that Satori supports for better type-safety.

/** @jsxRuntime automatic */
/** @jsxImportSource satori/jsx */

import satori from 'satori';
import { FC, JSXNode } from 'satori/jsx';

const MyComponent: FC<{ children: JSXNode }> = ({ children }) => (


{children}


)

const svg = await satori(
  <MyComponent>hello, world</MyComponent>,
  options,
)

Use without JSX

If you don't have JSX transpiler enabled, you can simply pass React-elements-like objects that have type, props.children and props.style (and other properties too) directly:

await satori(
  {
    type: 'div',
    props: {
      children: 'hello, world',
      style: { color: 'black' },
    },
  },
  options
)

HTML Elements

Satori supports a limited subset of HTML and CSS features, due to its special use cases. In general, only these static and visible elements and properties that are implemented.

For example, the <input> HTML element, the cursor CSS property are not in consideration. And you can't use <style> tags or external resources via <link> or <script>.

Also, Satori does not guarantee that the SVG will 100% match the browser-rendered HTML output since Satori implements its own layout engine based on the SVG 1.1 spec.

You can find the list of supported HTML elements and their preset styles here.

Images

You can use <img> to embed images. However, width, and height attributes are recommended to set:

await satori(
  <img src="https://picsum.photos/200/300" width={200} height={300} />,
  options
)

When using background-image, the image will be stretched to fit the element by default if you don't specify the size.

If you want to render the generated SVG to another image format such as PNG, it would be better to use base64 encoded image data (or buffer) directly as props.src so no extra I/O is needed in Satori:

await satori(
  <img src="https://github.com/vercel/satori/raw/0.27.2/data:image/png;base64,..." width={200} height={300} />,
  // Or src={arrayBuffer}, src={buffer}
  options
)

CSS

Satori uses the same Flexbox layout engine as React Native, and it’s not a complete CSS implementation. However, it supports a subset of the spec that covers most common CSS features:

Property Property Expanded Supported Values Example
CSS Variables Supported, including --var-name declaration and var(--var-name) usage with fallback values Example
display flex, contents, none, default to flex
position relative, static and absolute, default to relative
color Supported
margin
marginTopSupported
marginRightSupported
marginBottomSupported
marginLeftSupported
Position
topSupported
rightSupported
bottomSupported
leftSupported
Size
widthSupported
heightSupported
Min & max size
minWidthSupported except for min-content, max-content and fit-content
minHeightSupported except for min-content, max-content and fit-content
maxWidthSupported except for min-content, max-content and fit-content
maxHeightSupported except for min-content, max-content and fit-content
border
Width (borderWidth, borderTopWidth, ...)Supported
Style (borderStyle, borderTopStyle, ...)solid and dashed, default to solid
Color (borderColor, borderTopColor, ...)Supported
Shorthand (border, borderTop, ...)Supported, i.e. 1px solid gray
borderRadius
borderTopLeftRadiusSupported
borderTopRightRadiusSupported
borderBottomLeftRadiusSupported
borderBottomRightRadiusSupported
ShorthandSupported, i.e. 5px, 50% / 5px
Flex
flexDirectioncolumn, row, row-reverse, column-reverse, default to row
flexWrapwrap, nowrap, wrap-reverse, default to wrap
flexGrowSupported
flexShrinkSupported
flexBasisSupported except for auto
alignItemsstretch, center, flex-start, flex-end, baseline, normal, default to stretch
alignContentSupported
alignSelfSupported
justifyContentSupported
gapSupported
Font
fontFamilySupported
fontSizeSupported
fontWeightSupported
fontStyleSupported
Text
tabSizeSupported
textAlignstart, end, left, right, center, justify, default to start
textIndentSupported, including negative values (hanging indent)
textTransformnone, lowercase, uppercase, capitalize, defaults to none
textOverflowclip, ellipsis, defaults to clip
textDecorationSupport line types underline and line-through, and styles dotted, dashed, double, solidExample
textShadowSupported
lineHeightSupported
letterSpacingSupported
whiteSpacenormal, pre, pre-wrap, pre-line, nowrap, defaults to normal
wordBreaknormal, break-all, break-word, keep-all, defaults to normal
textWrapwrap, balance, defaults to wrap
Background
backgroundColorSupported, single value
backgroundImagelinear-gradient, repeating-linear-gradient, radial-gradient, repeating-radial-gradient, url, single value
backgroundPositionSupport single value
backgroundSizeSupport cover, contain, auto, and two-value sizes i.e. 10px 20%

Extension points exported contracts — how you extend this code

Matchers (Interface)
(no doc)
test/utils.tsx
CSSProperties (Interface)
(no doc)
test/css-variables.test.tsx
LayoutContext (Interface)
(no doc)
src/layout.ts
ParsedTransformOrigin (Interface)
(no doc)
src/transform-origin.ts
FontOptions (Interface)
(no doc)
src/font.ts
MaskProperty (Interface)
(no doc)
src/parser/mask.ts
ElementAttributesProperty (Interface)
(no doc)
src/jsx/jsx-runtime.ts
Background (Interface)
(no doc)
src/builder/background-image.ts

Core symbols most depended-on inside this repo

satori
called by 416
src/satori.ts
toImage
called by 406
test/utils.tsx
toMatchImageSnapshot
called by 405
test/utils.tsx
buildXMLString
called by 67
src/utils.ts
initFonts
called by 43
test/utils.tsx
lengthToNumber
called by 34
src/utils.ts
detectLanguageCode
called by 27
src/language.ts
get
called by 23
src/font.ts

Shape

Function 217
Interface 78
Method 17
Class 4

Languages

TypeScript100%

Modules by API surface

src/jsx/intrinsic-elements.ts60 symbols
src/utils.ts26 symbols
src/font.ts22 symbols
playground/pages/index.tsx14 symbols
src/text/index.ts11 symbols
src/handler/expand.ts11 symbols
src/handler/image.ts10 symbols
src/builder/gradient/radial.ts9 symbols
src/parser/shape.ts8 symbols
src/builder/border-radius.ts8 symbols
playground/utils/font.ts8 symbols
test/utils.tsx6 symbols

Dependencies from manifests, versioned

@babel/runtime7.19.0 · 1×
@monaco-editor/react4.4.5 · 1×
@resvg/resvg-js2.1.0 · 1×
@resvg/resvg-wasm2.3.1 · 1×
@shuding/opentype.js1.4.0-beta.0 · 1×
@types/blob-stream0.1.30 · 1×
@types/node16 · 1×
@types/opentype.js1.3.3 · 1×
@types/pdfkit0.12.7 · 1×
@types/react17.0.38 · 1×
@types/react-dom18.0.6 · 1×
@types/svg-to-pdfkit0.1.0 · 1×

For agents

$ claude mcp add satori \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact