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 从公开仓库中收录这些内容。

举报或申请下架