UI

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

1024 × 1024
Loading interactive preview…

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

1536 × 864

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

896 × 1120

Generation lifecycle

Canvas reveal phases

PhaseProgressVisual behavior
Idle0%Subtle neutral dot grid with prompt suggestions on the empty canvas.
Halftone wave0%–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 halftone20%–78%Dots sample the downscaled preview colors at their cell and grow by darkness, forming a colored halftone first under the wave then everywhere.
Dissolve80%–100%Dots blur and fade while the sharp image emerges cleanly on the final frame.
Upscale sweep0%–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 / ErrorAnyThe dot field freezes in place behind an icon-and-label overlay with a Retry image N button for that variation.

Bar actions

ControlBehavior
FilmstripFour variation tiles, each running its own mini DotField (4px pitch). Selecting any tile crossfades it onto the main stage.
UpscaleRuns onUpscale (or doubles pixel dimensions locally) with the sweeping dot-band mask and updates the dimensions pill.
VaryStarts a fresh batch of four variations with request.variationOf set to the active image and keeps the batch’s aspect ratio.
DownloadCalls 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.

ArgumentType / defaultDescription
defaultPromptstringDefault: "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.
placeholderstringDefault: "Describe the image you want"Hint text inside the prompt textarea. Defaults to "Describe the image you want".
modelsImageGenModel[]—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.
defaultModelstring—Id of the model selected first. Defaults to the first model.
aspectRatiosImageGenAspect[]—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.
defaultAspectRatiostring—Id of the aspect selected first. Defaults to the first aspect.
suggestionsstring[]—Prompts offered on the empty canvas before the first generation; up to three show. Defaults to four samples.
autoGeneratebooleanDefault: falseRun one simulated generation when the card first scrolls into view. Opt-in demo behavior; never fires when onGenerate is wired.
generateActionstring—Registered host action requested when Generate is pressed with onGenerate wired.
upscaleActionstring—Registered host action requested when Upscale is pressed with onUpscale wired.
downloadActionstring—Registered host action requested when Download is pressed with onDownload wired.
recipestudio | softDefault: "studio"Visual treatment. Both recipes preserve interaction behavior.
themeImageGenerationThemeDefault: {}Color mode, accent, and typed semantic token overrides.
motionnone | subtle | expressiveDefault: "subtle"Animation preset. System reduced-motion preferences take precedence.
motionOptionsImageGenerationMotionOptionsDefault: {}Crossfade, sweep, and wave timing overrides in milliseconds.
dirltr | rtl—Reading direction; inherited from the page when omitted.
  • ImageGenModel accepts { id, name, brand?, color? }. Model IDs must be unique (1–8 models).
  • ImageGenAspect accepts { id, label, width, height }. Aspect IDs must be unique (1–6 ratios).
  • ImageGenImage accepts { id, src, alt, width?, height?, seed? }.

React integration

PropPurpose
prompt / onPromptChangeControlled prompt text and change callback.
model / onModelChangeControlled model ID and selection callback.
aspectRatio / onAspectRatioChangeControlled 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).
presetApplication defaults overridden by explicit instance arguments.
tokensCSS variables applied after the typed theme, forwarded to the root card, buttons, and model tooltips.
ref, className, styleApplied to the root <section> element.
Native attributesid, aria-*, data-*, and remaining <section> props forwarded to the root element.

Keyboard & accessibility

KeyAction
Mod+EnterStarts generation from the prompt textarea when idle.
EscapeStops a running generation anywhere inside the card; finished variations are kept.
ArrowLeft / ArrowRightMoves between model chips, aspect-ratio chips, or filmstrip variations (respects RTL).
ArrowUp / ArrowDownMoves to the previous or next radio option in the focused group.
Home / EndJumps to the first or last option in the focused radio group.
TabMoves 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 roving tabIndex. Collapsed model chips preserve their full model name as aria-label and in a keyboard-accessible tooltip.
  • The active canvas exposes role="img" labelled with the finished image’s alt text (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 below 440px (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 groupCSS 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": []
}

On this page