Image

作者 vercel-labsfc2a696a50a3無授權條款18K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫昨天更新

Image renderer for json-render that turns JSON specs into SVG and PNG images via Satori. Use when working with @json-render/image, generating OG images from JSON, creating social cards, or rendering AI-generated image specs.

AI 產生的概覽

透過 Satori 將 JSON 規格渲染成 SVG 與 PNG 影像,包括 OG 圖與社群卡片。

功能
使用 Satori 將 JSON 規格轉換為 SVG 字串或 PNG 緩衝區,包含 Frame 根容器以及版面、內容與裝飾類元件。提供 schema、標準元件註冊表與目錄定義,並支援以 zod 定義自訂元件。適用於 OG 圖、社群卡片與 AI 生成的影像規格。
適用情境
在處理 @json-render/image、需要從 JSON 規格渲染或產生影像(如 OG 圖或社群卡片)時使用。也適用於從 AI 生成的規格產出影像,或以自訂元件擴充目錄的情境。
執行需求
需在 JavaScript/TypeScript 環境中執行,依賴 @json-render/image 套件(Satori);渲染 PNG 時另需 @resvg/resvg-js,並提供字型資料。不包含指令碼,僅為說明文件。

@json-render/image

Image renderer that converts JSON specs into SVG and PNG images using Satori.

Quick Start

typescript
import { renderToPng } from "@json-render/image/render";import type { Spec } from "@json-render/core";
const spec: Spec = {  root: "frame",  elements: {    frame: {      type: "Frame",      props: { width: 1200, height: 630, backgroundColor: "#1a1a2e" },      children: ["heading"],    },    heading: {      type: "Heading",      props: { text: "Hello World", level: "h1", color: "#ffffff" },      children: [],    },  },};
const png = await renderToPng(spec, {  fonts: [{ name: "Inter", data: fontData, weight: 400, style: "normal" }],});

Using Standard Components

typescript
import { defineCatalog } from "@json-render/core";import { schema, standardComponentDefinitions } from "@json-render/image";
export const imageCatalog = defineCatalog(schema, {  components: standardComponentDefinitions,});

Adding Custom Components

typescript
import { z } from "zod";
const catalog = defineCatalog(schema, {  components: {    ...standardComponentDefinitions,    Badge: {      props: z.object({ label: z.string(), color: z.string().nullable() }),      slots: [],      description: "A colored badge label",    },  },});

Standard Components

ComponentCategoryDescription
FrameRootRoot container. Defines width, height, background. Must be root.
BoxLayoutContainer with padding, margin, border, absolute positioning
RowLayoutHorizontal flex layout
ColumnLayoutVertical flex layout
HeadingContenth1-h4 heading text
TextContentBody text with full styling
ImageContentImage from URL
DividerDecorativeHorizontal line separator
SpacerDecorativeEmpty vertical space

Key Exports

ExportPurpose
renderToSvgRender spec to SVG string
renderToPngRender spec to PNG buffer (requires @resvg/resvg-js)
schemaImage element schema
standardComponentsPre-built component registry
standardComponentDefinitionsCatalog definitions for AI prompts

Sub-path Exports

ExportDescription
@json-render/imageFull package: schema, components, render functions
@json-render/image/serverSchema and catalog definitions only (no React/Satori)
@json-render/image/catalogStandard component definitions and types
@json-render/image/renderRender functions only

來源與署名

來源:vercel-labs/json-render位於skills/image提交fc2a696

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架