Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
ac65d76
feat(void): add next/og-compatible ImageResponse in void/og
ogawa0071 Oct 16, 2026
e58484e
test(void): type the Miniflare runtime in the void/og integration test
ogawa0071 Oct 16, 2026
168ca02
fix(void): draw CJK and accented Latin text in void/og images
ogawa0071 Oct 16, 2026
4cd7039
Cite upstream sources in void/og and isolate fonts per image
ogawa0071 Oct 18, 2026
549df6c
Fix void/og review findings
ogawa0071 Oct 19, 2026
5708c55
Cover void/og's documented failure paths and fix the guide
ogawa0071 Oct 22, 2026
0568539
Keep Latin text on Geist and cache emoji in void/og
ogawa0071 Oct 27, 2026
d0fcfa2
Fetch images once per void/og render and hash each font buffer once
ogawa0071 Oct 27, 2026
67ddcd0
Show void/og in a .tsx route now that routes accept JSX
ogawa0071 Nov 3, 2026
e043deb
Move void/og to takumi-js ~2.18.2
ogawa0071 Nov 3, 2026
f901979
Test the ~ range in void/og's Node.js check and note how to verify a fix
ogawa0071 Nov 3, 2026
ee692d6
Use measured CPU figures in the void/og guide
ogawa0071 Nov 3, 2026
fb6c5b9
fix(void): find void's package.json without assuming the module's depth
yangshun Nov 11, 2026
45549a3
docs(og): note the renderer's Worker size on Cloudflare
yangshun Nov 11, 2026
e349d90
fix(og): let lang choose the Chinese, Japanese or Korean font before …
yangshun Nov 11, 2026
62abc05
fix(og): drop only the fallback font files that fail to download
yangshun Nov 11, 2026
94ea12a
fix(og): draw bold fallback text with the fonts' weight axis
yangshun Nov 11, 2026
a244dfa
docs(og): describe void/og on its own
yangshun Nov 11, 2026
c71e701
chore(og): upgrade takumi-js to 2.20
yangshun Nov 12, 2026
f4626cc
refactor(og): declare ImageResponseOptions instead of passing Takumi'…
yangshun Nov 12, 2026
558d08c
docs(og): explain void/og behavior without citing other libraries
yangshun Nov 12, 2026
ee858db
fix(og): accept any font weight from 1 to 1000
yangshun Nov 12, 2026
516eb60
fix(og): draw ・ and ー with the Japanese fallback family
yangshun Nov 12, 2026
1b77583
refactor(og): move font handling into og-fonts.ts
yangshun Nov 12, 2026
41fe825
perf(og): ask Google Fonts for only the characters in the image
yangshun Nov 12, 2026
f401897
feat(og): add fallbackFonts to turn off Google Fonts downloads
yangshun Nov 12, 2026
fc1c73a
docs(og): note font memory growth in the Node.js, Bun and Deno section
yangshun Nov 12, 2026
47472e0
fix(og): send one Cache-Control header in development and builds
yangshun Nov 12, 2026
fe5d43a
docs(og): trim the void/og notes in the package AGENTS.md
yangshun Nov 12, 2026
1f551df
docs(og): describe the renderer's size without Cloudflare's limits
yangshun Nov 12, 2026
f9262ad
fix(og): keep Han characters when Korean text also has Hangul
yangshun Nov 12, 2026
1d1b3bf
docs(og): load the example font from Google Fonts
yangshun Nov 12, 2026
d37dd48
docs(og): say which fonts draw text and name the Noto fallback
yangshun Nov 12, 2026
14189bd
chore: add ImageResponse playground
kossnocorp Nov 12, 2026
14a46db
chore: expose `renderImage`'s options type
kossnocorp Nov 12, 2026
2c927d6
feat: move ImageResponse to void/image, add OgImageResponse
kossnocorp Nov 12, 2026
8052d0a
chore: get rid of installing takumi-js requirement
kossnocorp Nov 13, 2026
fc94436
chore: make Inter the default font in ImageResponse
kossnocorp Nov 13, 2026
7130279
chore: make ImageResponse & OgImageResponse only accept sanitized str…
kossnocorp Nov 13, 2026
364d3d4
chore: don't set headers in ImageResponse, cache agressively in OgIma…
kossnocorp Nov 13, 2026
8edb517
chore: add ImageResponse memory test playground
kossnocorp Nov 13, 2026
a96365c
feat: add `preset` option to `OgImageResponse` with common image sizes
kossnocorp Nov 13, 2026
c47c942
chore: implement custom fonts caching for ImageResponse
kossnocorp Nov 13, 2026
625b36f
chore: cut down `ImageResponse`-related AGENTS.md fluff
kossnocorp Nov 13, 2026
61ad3bb
chore: extract void/image + void/og -> @void/image/generate
kossnocorp Nov 17, 2026
60f5c32
chore: set up build + deployment + latency benchmark suite
kossnocorp Nov 17, 2026
c858759
chore: fix all jsDelivr images detected as emojis, prevent custom fam…
kossnocorp Nov 17, 2026
281fedd
chore: remove direct dependence on Takumi types
kossnocorp Nov 17, 2026
5c9cd37
chore: make image response classes lazy, add `renderImage` and `rende…
kossnocorp Nov 17, 2026
76d4cfa
chore: get rid of OgImageResponse presets in favor of docs
kossnocorp Nov 17, 2026
85f0570
chore: clean up image response code
kossnocorp Nov 17, 2026
eb15699
chore: rework image generation to use Cloudflare Browser Run first to…
kossnocorp Nov 19, 2026
3f9a20e
chore: update benchmarks, fix pnpm-lock.yaml
kossnocorp Nov 20, 2026
4de5272
chore: upgrade Takumi to fix crash and simplify cache system
kossnocorp Nov 20, 2026
13e59d5
chore: fix Takumi renderer to resolve correct version
kossnocorp Nov 20, 2026
9149f9c
chore: fix cache header to omit in dev for OG renderer instead of a m…
kossnocorp Nov 20, 2026
41dcb3e
chore: clarify image gen docs
kossnocorp Nov 20, 2026
3e965a3
chore: extract `void-image-takumi` as 3rd-party package
kossnocorp Nov 27, 2026
cdf402c
chore: add failing tests for missing image gen coverage
kossnocorp Nov 27, 2026
26932de
chore: add missing browser binding to provisioning
kossnocorp Nov 29, 2026
86cd7a3
chore: fix async content in generated images
kossnocorp Nov 30, 2026
beeb486
chore: tighten custom image renderer types
kossnocorp Nov 30, 2026
5215446
chore: support image generation while prerendering
kossnocorp Nov 30, 2026
facc478
chore: add prerender example to image-gen playground
kossnocorp Nov 30, 2026
2ea64ab
chore: document where images render
kossnocorp Nov 30, 2026
3ded8de
chore: fix formatting after rebase
kossnocorp Nov 30, 2026
6bfde5b
chore: fix image prerender types
kossnocorp Nov 30, 2026
5ae4851
chore: move image generation benchmark to its own branch
kossnocorp Nov 30, 2026
6fbaf51
chore: integrate Browser Run with billing
kossnocorp Dec 1, 2026
91f5341
chore: clean up PR branch
kossnocorp Dec 1, 2026
2f86acc
chore: commit pnpm-lock.yaml
kossnocorp Dec 1, 2026
be62c7a
chore: fix lint issues
kossnocorp Dec 1, 2026
289e606
chore: update `void-image-takumi` location
kossnocorp Dec 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/scripts/packed-consumer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ for (const entry of readdirSync(join(root, 'packages'), { withFileTypes: true })
continue;
}
const directory = join(root, 'packages', entry.name);
if (!existsSync(join(directory, 'package.json'))) {
continue;
}
const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
if (manifest.private) {
continue;
Expand Down Expand Up @@ -257,6 +260,15 @@ try {
);
const cli = join(fixture, 'node_modules/void/dist/cli/cli.mjs');
await run(process.execPath, [cli, '--help'], fixture);
await run(
process.execPath,
[
'--input-type=module',
'-e',
"import assert from 'node:assert/strict'; import { ImageResponse, OgImageResponse } from 'void/image'; assert(ImageResponse && OgImageResponse); await assert.rejects(import('void/og')); await assert.rejects(import('@void/image'));",
],
fixture,
);
if (full && framework === 'react') {
await run(
manager,
Expand Down Expand Up @@ -590,11 +602,7 @@ if (runtime.manifest.platformVersion !== ${JSON.stringify(version)}) throw new E
if (framework === 'react') {
// The Node target bundles the installed void into its build, so a ValidationError from
// void/handler is the class that page actions check, as in dev.
await run(
manager,
manager === 'npm' ? ['install', '@hono/node-server'] : ['add', '@hono/node-server'],
fixture,
);
await run(manager, [manager === 'npm' ? 'install' : 'add', '@hono/node-server'], fixture);
writeFileSync(
join(fixture, 'void.config.ts'),
"import { defineConfig } from 'void/config';\nexport default defineConfig({ target: 'node' });\n",
Expand Down
4 changes: 4 additions & 0 deletions .github/scripts/packed-registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export function inspectPackage(tarball) {
assert(isHttpsUrl(manifest.homepage), `${manifest.name}: homepage must be an HTTPS URL`);
assert(isHttpsUrl(manifest.bugs?.url), `${manifest.name}: bugs.url must be an HTTPS URL`);
assert(files.has('package/LICENSE'), `${manifest.name}: missing packaged LICENSE`);

if (manifest.name === 'void') {
assert(manifest.exports['./image'], 'void: missing image export');
assert.equal(manifest.exports['./og'], undefined);
for (const file of [
'docs/guide/quickstart.md',
'docs/reference/cli.md',
Expand All @@ -44,6 +47,7 @@ export function inspectPackage(tarball) {
'void: docs must be bundled at the package root',
);
}

for (const field of [
'dependencies',
'optionalDependencies',
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Read the [Void documentation](https://void.cloud) online or use the Markdown gui

- [Server routes](https://void.cloud/guide/server-routing), [pages](https://void.cloud/guide/pages-routing/overview), and [error components](https://void.cloud/guide/pages-routing/errors)
- [Database](https://void.cloud/guide/database) and [type safety](https://void.cloud/guide/type-safety)
- [Image generation](https://void.cloud/guide/image-generation) and [Open Graph images](https://void.cloud/guide/og-images) with `void/image`
- [Deployment](https://void.cloud/guide/deployment)
- [Framework integrations](https://void.cloud/integrations/frameworks/overview)
- [API](https://void.cloud/reference/api) and [CLI](https://void.cloud/reference/cli) reference
Expand Down
3 changes: 2 additions & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ workspace links can hide. They do not publish packages or deploy applications.

Smoke coverage checks package contents and exports, real initialization, CLI help, a frozen
reinstall, public Vite builds, TypeScript, and development HTTP requests for pages, assets, and
KV. It uses no browser. Full coverage adds Vue, Svelte, Solid, Markdown, production preview,
KV. It also verifies that the public `void/image` entry loads. It uses no browser.
Full coverage adds Vue, Svelte, Solid, Markdown, production preview,
and browser hydration/navigation. Superseded PR/main runs are cancelled; release runs are not.

The selector reads all PR file pages or the complete pushed commit range. Renames consider both
Expand Down
3 changes: 3 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const referenceItems: Array<SidebarItem> = [
{ text: 'Deployment artifacts', link: '/reference/api/deploy' },
{ text: 'Database and Seeding', link: '/reference/api/database' },
{ text: 'Resource Clients', link: '/reference/api/resources' },
{ text: 'HTML Templates', link: '/reference/api/html' },
{ text: 'Types', link: '/reference/api/types' },
{ text: 'Environment Variables', link: '/reference/api/env' },
{ text: 'Pages Adapters', link: '/reference/api/pages' },
Expand Down Expand Up @@ -329,6 +330,8 @@ export default extendConfig(
},
{ text: 'Custom SSR', link: '/guide/ssr' },
{ text: 'SSG', link: '/guide/ssg' },
{ text: 'Image Generation', link: '/guide/image-generation' },
{ text: 'Open Graph Images', link: '/guide/og-images' },
],
},
{
Expand Down
235 changes: 235 additions & 0 deletions docs/guide/image-generation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---
outline: deep
---

# Image Generation

Use `ImageResponse` from `void/image` to generate PNGs for favicons, badges, and banners from your app's data.

Void renders HTML and CSS with [Cloudflare Browser Run](https://developers.cloudflare.com/browser-run/) or Chromium locally.

For social previews, use [`OgImageResponse`](./og-images.md).

## Setup

Importing `void/image` adds a Browser Run binding named `BROWSER` to your app. `void dev`, `vp preview` and build-time [prerendering](./edge/prerendering.md) render with local Chromium.

To use Browser Run in your Cloudflare account during `void dev`, declare the binding in `void.config.ts` and set `remote: true`:

```ts
import { defineConfig } from 'void/config';

export default defineConfig({
cloudflare: {
browser: {
binding: 'BROWSER',
remote: true,
},
},
});
```

If you haven't connected the project yet, run `void connect --platform cloudflare`.

The binding works with direct Cloudflare deploys and Void platform deploys:

- With `void deploy --platform cloudflare`, rendering uses your own account's [Browser Run limits](https://developers.cloudflare.com/browser-run/limits/) and pricing. When Cloudflare rate limits the account, rendering rejects with `UsageLimit` from `void/limits`.
- On a Void platform, rendering counts toward your account's monthly Browser Run allowance, which the platform's plan sets. Over the allowance, rendering rejects with `UsageLimit` from `void/limits` until the next billing period. The platform's plan also limits how often each app can render; over that limit, `UsageLimit` carries a `retryAt` time. The binding supports Browser Run [Quick Actions](https://developers.cloudflare.com/browser-run/quick-actions/) on the default browser, except `json`. Browser Sessions (Puppeteer, Playwright, and CDP) need a direct Cloudflare deploy. Deploying an app with Browser Run requires a platform release that supports it. On an older platform, `void deploy` stops before building and asks you to upgrade the platform.

### JSX Types

`void/image` uses [Hono JSX](https://hono.dev/docs/guides/jsx) through `void/jsx`. You can write `.tsx` image routes in a project that doesn't use React without installing `react`, `react-dom`, or `@types/react`. React elements and components aren't accepted as image input. If you prefer not to configure JSX, use [HTML templates](#html-templates) in a `.ts` route.

Configure Hono JSX in one of two ways:

- **Per file:** If your app already uses another JSX runtime, keep its settings and add `/** @jsxImportSource void/jsx */` at the top of each `.tsx` file that uses Hono JSX.

- **Project-wide:** If your app doesn't use another JSX runtime, configure `tsconfig.json` as shown below, keeping any existing entries in `compilerOptions.types`. Despite its name, `"jsx": "react-jsx"` enables TypeScript's automatic JSX transform; `"jsxImportSource": "void/jsx"` selects Hono instead of React.

```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "void/jsx",
"types": ["void/jsx"]
}
}
```

Match the import source in your [Vite JSX settings](./server-routing.md#jsx-handlers).

The examples below assume the project-wide setup.

## Usage

Return an `ImageResponse` from a `.tsx` route:

```tsx
// routes/favicon.png.tsx
import { defineHandler } from 'void';
import { ImageResponse } from 'void/image';

export const GET = defineHandler(() => {
return new ImageResponse(
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
height: '100%',
borderRadius: 12,
background: '#0f172a',
color: 'white',
fontSize: 48,
fontWeight: 700,
}}
>
V
</div>,
{ width: 64, height: 64 },
);
});
```

`GET /favicon.png` returns a 64 × 64 PNG. Add a favicon link to your page's `<head>` (with [`head()`](./pages-routing/head.md) in Pages mode):

```html
<link rel="icon" type="image/png" sizes="64x64" href="/favicon.png" />
```

### HTML templates

In a `.ts` route, use the [`html` template tag from `void/html`](../reference/api/html.md). It escapes interpolated text automatically:

```ts
// routes/badge.png.ts
import { defineHandler } from 'void';
import { html } from 'void/html';
import { ImageResponse } from 'void/image';

export const GET = defineHandler((c) => {
const label = c.req.query('label') ?? 'Built with Void';
return new ImageResponse(
html`<div style="padding: 16px; background: #0f172a; color: white; font-size: 24px">
${label}
</div>`,
{ width: 320, height: 64 },
);
});
```

The image APIs accept Hono JSX and escaped HTML templates, including asynchronous templates without an extra `await`. Use `ImageInput` from `void/image` to type reusable content. Plain strings are not accepted.

### CSS and images

Use inline styles or a `<style>` block. JavaScript does not run in the screenshot page. Use public HTTPS URLs or data URLs for image assets. Keep the markup trusted: interpolate request text as text, and validate any request values used as asset URLs.

Chromium renders emoji with its system fonts. To use specific artwork, put an SVG or PNG in the markup with an `<img>` element.

## Await rendering

Use `renderImage(content, options)` for PNG bytes or to catch rendering failures before sending an HTTP response:

```ts
import { defineHandler } from 'void';
import { html } from 'void/html';
import { renderImage } from 'void/image';

export const GET = defineHandler(async (c) => {
try {
const png = await renderImage(html`<div>Built with Void</div>`, {
width: 800,
height: 400,
});
return new Response(png, { headers: { 'Content-Type': 'image/png' } });
} catch {
return c.text('Image generation failed', 500);
}
});
```

`renderImage` returns a `Promise<Uint8Array>` and sets no HTTP headers. In Void route handlers and Pages actions, an uncaught `UsageLimit` returns a structured HTTP 429. For social previews with default dimensions, use [`renderOgImage`](./og-images.md#await-rendering).

`ImageResponse` and `OgImageResponse` start rendering when their body is read. Rendering failures reject body consumption. Cancelling an unread body prevents rendering; cancelling after rendering starts discards the result without interrupting the render.

## Options

Use `RenderImageOptions` for rendering options and `ImageResponseOptions` for rendering and HTTP response options. Both types are exported by `void/image`.

| Option | Default | Description |
| --------------------------------- | ------------------ | ------------------------------------------------------------------ |
| `width`, `height` | Required | Positive integer dimensions in pixels. |
| `font` | Roboto, sans-serif | A font family or an ordered list of families. See [Fonts](#fonts). |
| `fonts` | | Custom font faces. |
| `lang` | | Document language, such as `'ja'` or `'zh-TW'`. |
| `debug` | `false` | Draws outlines around elements. |
| `status`, `statusText`, `headers` | | HTTP options for `ImageResponse`. |

`ImageResponse` sets `Content-Type: image/png` unless you override it.

## Fonts

Text uses Roboto by default. Use `font` to choose a [family installed in Browser Run](https://developers.cloudflare.com/browser-run/reference/supported-fonts/) or provide an ordered list. Chromium looks for each glyph in that order, then uses system fallback:

```ts
import { html } from 'void/html';
import { ImageResponse } from 'void/image';

export const GET = () =>
new ImageResponse(html`<div>Hello, 世界</div>`, {
width: 800,
height: 400,
lang: 'ja',
font: ['Roboto', 'Noto Sans CJK JP', 'sans-serif'],
});
```

For a custom font, add a named face to `fonts` and select its name in `font` or in your markup's CSS. `data` accepts an `ArrayBuffer`, a `Uint8Array`, or `{ url: string }` pointing to an HTTPS font file. If you use Google Fonts, pass the font file URL, not the stylesheet URL.

```ts
import { html } from 'void/html';
import { ImageResponse } from 'void/image';

export const GET = () =>
new ImageResponse(html`<div>Built with Void</div>`, {
width: 800,
height: 400,
fonts: [{ name: 'Brand', data: { url: 'https://example.com/fonts/brand.woff2' } }],
font: ['Brand', 'Roboto'],
});
```

Set `weight` (1–1000) for a single weight or omit it for a variable face. Set `style: 'italic'` to register an italic face.

## Cache generated images

Each request that reaches your handler renders a new image. To reuse renders at the edge, configure [revalidation](./edge/revalidation.md):

```ts
import { defineConfig } from 'void/config';

export default defineConfig({
routing: {
revalidate: {
'/favicon.png': 86400,
},
},
});
```

Add this setting to your existing `void.config.ts`. Void doesn't cache paths under `/api`. If query parameters affect the image, list them in [`routing.revalidateQueryAllowlist`](../reference/config.md#routing-revalidatequeryallowlist) or put those values in the path.

## Third-party renderer

See [void-image-takumi](https://github.com/yangshun/void-image-takumi) for browser-free rendering.

If every image in your app uses a third-party renderer, turn off the Browser Run binding:

```ts
import { defineConfig } from 'void/config';

export default defineConfig({
inference: { bindings: { browser: false } },
});
```
Loading