result
Edit card
Combine this card with the composer bar in edit mode. Apply draggable bounding boxes to an image to create precise edit regions. Each region contains a prompt for the selected image editing model. Paginate from the original image to each edited image.
Code snippet
The bare minimum is an image editor for marking regions on an attached image and editing them with Flux 3 Image.
For the stylesheets and the server route that holds your API keys, see Develop.
import { useState } from "react";import { Composer, EditCard, EDIT_IMAGE_USE_CASE, createFalEngine, useComposer, type ComposerAttachment,} from "@chai-ui/react";
const engine = createFalEngine({ outputKind: "image" });
export function ImageEditor() { const [value, setValue] = useState(""); const [attachments, setAttachments] = useState<ComposerAttachment[]>([]); const editImage = attachments.find((a) => a.kind === "image") ?? null; const { submit, cancel, edit } = useComposer({ engine, editImage }); const busy = edit?.versions.some((v) => v.status === "queued" || v.status === "running") ?? false;
return ( <> {edit && <EditCard {...edit} />} <Composer value={value} onChange={setValue} attachments={attachments} onAttachmentsChange={setAttachments} useCase={EDIT_IMAGE_USE_CASE} regions={edit?.regions} onRegionsChange={edit?.onRegionsChange} onSubmit={submit} submitting={busy} onAbort={cancel} /> </> );}Preview controls
The two changes from the design, green lips and "Boss" instead of "Manager", added to any regions already there. Then press submit in the Composer.
Back to the demo photo, with no regions or versions.
The next edit fails, so the failed state is reachable without a real failing model.
A model's maxRegions: "New region" turns off once two regions are on the image.
scale: the card starts at this percentage of the image's own width. Try 30 with a large photo and raise the max width. Leave empty to fill the max size.
width: a fixed starting width when there's no scale. Leave empty to fill the max size.
maxWidth: the widest the card gets. Defaults to 630. With no scale or fixed width, the card fills max width × max height, keeping the image's shape. It's never wider than the page.
maxHeight: the tallest the card gets. A tall image narrows the card to fit. Defaults to 630.
