Image generation
AI image studio card with a dot-matrix halftone canvas reveal, four-variation filmstrip, sweeping halftone upscale, vary and download actions, and a prompt bar with model and aspect-ratio chips.
import { ImageGeneration } from '@uthereal/ui/image-generation'Image generation playground
Describe an image, then generate
Overview
ImageGeneration provides a self-contained text-to-image studio card. Each image forms on a device-pixel-ratio dot-matrix canvas where a soft halftone wave breathes and travels across the grid, samples colors from the incoming preview, grows into a colored halftone, and dissolves into the sharp image. A four-variation filmstrip runs its own mini dot fields beside Upscale, Vary, and Download, above a prompt bar with model and aspect-ratio radio chips.
Use ImageGeneration for marketing asset generators, product photography tools, and slide or document illustration flows where readers compare candidates and continue with one. For a full layer editor with inpainting masks, use a dedicated canvas library.
Usage
'use client'
import { ImageGeneration } from '@uthereal/ui/image-generation'
export function AssetStudio() {
return (
<ImageGeneration
onGenerate={async (request, { signal, onProgress }) => {
const res = await fetch('/api/images', {
method: 'POST',
signal,
body: JSON.stringify({
prompt: request.prompt,
model: request.model.id,
width: request.aspect.width,
height: request.aspect.height,
variationOf: request.variationOf?.id,
}),
})
if (!res.ok) throw new Error('Generation failed')
const job = await res.json()
onProgress?.(1, job.previewUrl)
return {
id: job.id,
src: job.url,
alt: request.prompt,
width: request.aspect.width,
height: request.aspect.height,
seed: job.seed,
}
}}
onDownload={(image) => {
window.open(image.src, '_blank', 'noopener')
}}
/>
)
}Omit onGenerate and onUpscale to run the built-in offline simulation: deterministic procedural SVG artworks encoded as data URIs with zero network requests.
Examples
Widescreen editorial studio
Set defaultAspectRatio="16:9" with a custom model roster and slide-oriented suggestions for widescreen hero graphics and deck illustrations.
Describe an image, then generate
Portrait product ratios
Supply vertical aspectRatios (4:5 and 9:16) and start on defaultAspectRatio="4:5" for social and catalog photography; the stage height caps at stageMaxHeight (440px by default) so tall shapes stay compact.
Describe an image, then generate
Generation lifecycle
Canvas reveal phases
| Phase | Progress | Visual behavior |
|---|---|---|
| Idle | 0% | Subtle neutral dot grid with prompt suggestions on the empty canvas. |
| Halftone wave | 0%–20% | A radial halftone lens wave breathes and wanders across neutral dots with a blurred glow twin; the status pill shows a 3×3 chasing dot ring. |
| Color halftone | 20%–78% | Dots sample the downscaled preview colors at their cell and grow by darkness, forming a colored halftone first under the wave then everywhere. |
| Dissolve | 80%–100% | Dots blur and fade while the sharp image emerges cleanly on the final frame. |
| Upscale sweep | 0%–100% | A vertical halftone band in the image’s colors sweeps left to right, revealing the sharp upscaled layer behind it and updating the size pill. |
| Stopped / Error | Any | The dot field freezes in place behind an icon-and-label overlay with a Retry image N button for that variation. |
Bar actions
| Control | Behavior |
|---|---|
| Filmstrip | Four variation tiles, each running its own mini DotField (4px pitch). Selecting any tile crossfades it onto the main stage. |
| Upscale | Runs onUpscale (or doubles pixel dimensions locally) with the sweeping dot-band mask and updates the dimensions pill. |
| Vary | Starts a fresh batch of four variations with request.variationOf set to the active image and keeps the batch’s aspect ratio. |
| Download | Calls onDownload or saves image.src locally with a prompt-slugged filename including variation index and dimensions. |
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
defaultPrompt | stringDefault: "Golden hour architectural pavilion reflected in still water, warm limestone and soft mist" | Prompt the card starts with. Defaults to a golden hour architectural pavilion sample. Edits do not reset a mounted instance. |
placeholder | stringDefault: "Describe the image you want" | Hint text inside the prompt textarea. Defaults to "Describe the image you want". |
models | ImageGenModel[]— | Model chips in the prompt bar. The active one shows its name; the others collapse to their 16px mark with a tooltip. Defaults to three generic samples. |
defaultModel | string— | Id of the model selected first. Defaults to the first model. |
aspectRatios | ImageGenAspect[]— | Output shape chips with their pixel sizes; they drive the canvas shape and the size label. Defaults to 1:1, 4:5 and 16:9. |
defaultAspectRatio | string— | Id of the aspect selected first. Defaults to the first aspect. |
suggestions | string[]— | Prompts offered on the empty canvas before the first generation; up to three show. Defaults to four samples. |
autoGenerate | booleanDefault: false | Run one simulated generation when the card first scrolls into view. Opt-in demo behavior; never fires when onGenerate is wired. |
generateAction | string— | Registered host action requested when Generate is pressed with onGenerate wired. |
upscaleAction | string— | Registered host action requested when Upscale is pressed with onUpscale wired. |
downloadAction | string— | Registered host action requested when Download is pressed with onDownload wired. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | ImageGenerationThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | ImageGenerationMotionOptionsDefault: {} | Crossfade, sweep, and wave timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
ImageGenModelaccepts{ id, name, brand?, color? }. Model IDs must be unique (1–8models).ImageGenAspectaccepts{ id, label, width, height }. Aspect IDs must be unique (1–6ratios).ImageGenImageaccepts{ id, src, alt, width?, height?, seed? }.
React integration
| Prop | Purpose |
|---|---|
prompt / onPromptChange | Controlled prompt text and change callback. |
model / onModelChange | Controlled model ID and selection callback. |
aspectRatio / onAspectRatioChange | Controlled aspect-ratio ID and selection callback. |
onGenerate(request, context) | Runs once per variation in parallel (index 0..3). Report progress (0..1) and an optional preview URL via context.onProgress; honor context.signal. |
onUpscale(image, context) | Upscales the active image and resolves with the higher-resolution ImageGenImage. |
onDownload(image) | Replaces the built-in browser download behavior. |
onSelect(image | null) | Fires when a finished variation is picked, finishes on the canvas, or completes upscaling; passes null when a new batch begins. |
onAction(action, itemId?) | Called with generateAction, upscaleAction (plus image ID), or downloadAction (plus image ID). |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme, forwarded to the root card, buttons, and model tooltips. |
ref, className, style | Applied to the root <section> element. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Mod+Enter | Starts generation from the prompt textarea when idle. |
Escape | Stops a running generation anywhere inside the card; finished variations are kept. |
ArrowLeft / ArrowRight | Moves between model chips, aspect-ratio chips, or filmstrip variations (respects RTL). |
ArrowUp / ArrowDown | Moves to the previous or next radio option in the focused group. |
Home / End | Jumps to the first or last option in the focused radio group. |
Tab | Moves across the active filmstrip variation, Upscale, Vary, Download, prompt, model, aspect, and Generate. |
- Model chips, aspect-ratio chips, and the filmstrip use
role="radiogroup"with rovingtabIndex. Collapsed model chips preserve their full model name asaria-labeland in a keyboard-accessible tooltip. - The active canvas exposes
role="img"labelled with the finished image’salttext (or the tile number and status while generating, stopped, or failed). - A pre-mounted polite
role="status"live region announces batch starts, completions, failures, retries, picks, upscales, and downloads, appending"Simulated, nothing was sent."when running offline. - Container queries reflow the card below
500px(wrapping the filmstrip into a scrollable row below actions) and below440px(hiding expanded model names so chips stay compact).@media (forced-colors: active)maps borders, active states, and spinner dots to system colors.
Motion & theming
The canvas springs to a new aspect ratio on the smooth spring (0.4s, bounce 0) while container resizes cut immediately without wobble. Model chips expand and collapse on the morph spring (0.42s, bounce 0.16), and status and dimension pills crossfade in place by key.
Under prefers-reduced-motion: reduce, the halftone wave rests in the center, images crossfade directly by progress, the 3×3 spinner freezes, the upscale sweep drops, and aspect changes cut immediately. Setting motion="none" makes every swap and transition immediate (0ms).
theme accepts mode, accent, and typed tokens across these groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-track, --ui-info, --ui-success, --ui-warning, --ui-tone-foreground, --ui-overlay, --ui-tint-strength |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
accentTones | --ui-accent-strong, --ui-accent-subtle |
type | --ui-font-mono, --ui-font-display |
component | --ui-image-generation-stage-max-height (440px default canvas height cap) |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, ImageGeneration is a leaf block. Configure defaultPrompt, models, aspectRatios, suggestions, and registered host actions (generateAction, upscaleAction, downloadAction). See Building with agents.
{
"type": "ImageGeneration",
"props": {
"defaultPrompt": "Minimalist glass conservatory in morning fog, soft natural light",
"defaultAspectRatio": "16:9",
"generateAction": "generate_images",
"upscaleAction": "upscale_image",
"downloadAction": "download_image"
},
"children": []
}