# GIF Studio: agent guide (browser contract 1.0)

- Workspace: https://www.fuzzpuppy.com/gif-studio
- Capabilities: https://www.fuzzpuppy.com/gif-studio/agent.json
- Guide: https://www.fuzzpuppy.com/gif-studio/agent.md
- Task routes: /create-gif, /edit-gif, /gif-viewer, /video-to-gif, /gif-to-video, /gif-frame-extractor, /reverse-gif, /gif-speed-changer.

All task routes use the same editor and browser API. Processing requires a JavaScript browser with workers, canvas and media decoding support. Video codecs vary by browser; compatibility preparation can download encoder code. No login, API key, server processing endpoint, or WebMCP is required or provided. User media stays in the tab. Refresh/navigation loses the project. Export and save before leaving.

## Inputs, outputs and limits

Open one GIF or video, or PNG/JPEG/still WebP images (naturally sorted by filename). Video extensions: MP4, MOV, WebM, MKV, M4V, AVI; decoding is codec-dependent. Animated WebP and APNG inputs are unsupported. Maximum selection: 300 MiB, 1,200 frames; source canvas: 16,777,216 pixels and 8,192 per edge. Prepared frames and exports are each bounded to 128 MiB. Working/output edges are at most 1,920 pixels.

Exports: GIF, WebM (default), silent MP4, transparent MOV, APNG; frame extraction produces PNG ZIPs. GIF has one-bit transparency; APNG supports smooth alpha; WebM preserves alpha for compatible players; MOV uses QuickTime Animation with alpha for video editors such as CapCut; MP4 flattens transparency to black. Video exports contain one cycle; the player controls looping. GIF/APNG timing is quantized to centiseconds. Always explicitly choose the desired format.

## Browser API

Wait until `window.fuzzPuppyGifStudio` exists. Keep that object; its methods use current editor state. This is a page JavaScript interface, not an HTTP API. It works on all task routes. Calls change the same project and controls the user sees. Do not operate the UI concurrently with API commands. Await asynchronous commands before starting another.

- `getState()` returns JSON-safe version, status, progress text, error, isDemo, sourceNames, preparation options, pendingSource (filenames and source metadata including full duration), frames (one-based indices, original durationMs and selection), currentFrame, project summary, exportSettings and result metadata. Project includes working dimensions, source frame count, playback frame count, durationSeconds, trim and edits. During preparation, the existing project can still describe the prior media; inspect status before acting.
- `importFiles(File[])` opens browser File objects. Alternatively set the file input labeled `Choose source media` with browser automation. Import cancels any pending demo. Inspect state afterward: small sources open immediately; larger or incompatible sources need preparation. A preloaded example is explicitly marked `isDemo: true`; replace it with user media before editing the user's file.
- `prepare(options?)` decodes the pending source using optional overrides: `start`/`end` in seconds, `fps` (1–50), `edge` (32–1920), `imageDuration` in milliseconds (20–10,000). Inspect preparation defaults before overriding. Compatibility conversion, if needed, can also be performed with the existing preparation UI.
- `configure({ edits?, trim?, format?, colors?, gifEdge?, gifFps? })` validates and atomically updates controls; invalid settings do not partially apply. Trim is a **one-based inclusive** pair of source-frame indices. Colors: 32, 64, 128 or 256. GIF edge: 0 (original), 240 or 360. GIF FPS: 0 (original), 10 or 15. Export options preserve project frames. Dimensions are explicit: set both width and height to preserve the intended aspect ratio.
- `edits` supports width/height (2–1920), cropX/cropY/cropWidth/cropHeight in source working pixels, rotation (0/90/180/270), flip (boolean), speed (0.1–8), direction (`forward`, `reverse`, `bounce`), repeat (-1 once, 0 infinite, or 1–65535), text, textTone (`light`/`dark`), textPosition (`top`/`center`/`bottom`). Other frame operations remain available through labeled UI controls.
- `export()` resolves to `{ filename, mimeType, byteSize, blob }` and also exposes the normal download button. `getResult()` returns that artifact or null. Editing invalidates the previous export.
- `extract(scope?)` returns a PNG ZIP artifact for `all` (default: included trimmed range), `selected` (UI-selected frames), or `current` (preview frame). It does not automatically download or replace the animation export. Read/save the returned Blob inside the page.
- `download()` triggers the existing animation download behavior. Register your automation client's download listener **before** calling it. `cancel()` aborts current processing; an awaited API operation rejects with code `CANCELLED`.

Statuses: empty, loading-demo, processing, preparation-required, embedded-tool, error, ready, completed. Progress is descriptive text, not a percentage. Command errors are Error objects with a `code` and `message`: BUSY, EMBEDDED_TOOL, NOT_READY, INVALID_INPUT, INVALID_CONFIGURATION, PROCESSING_FAILED, CANCELLED. Catch them inside page evaluation to serialize both fields. State error is readable text. Embedded background-removal/Clip Merge steps use their existing UI; return to GIF Studio before issuing editor API commands.

Blobs are local, not JSON serializable or public URLs. Use `download()` for animation files; for programmatic bytes read `await artifact.blob.arrayBuffer()` inside the page. Avoid serializing large byte arrays through automation; use browser downloads. Any object URL you create is tab-local and must be revoked after use. The adapter does not upload artifacts or persist projects.

## Recipes

### Reverse a GIF and export at 240px

```js
// First upload through the labeled file input or await api.importFiles(files).
const api = window.fuzzPuppyGifStudio;
// If status is preparation-required, await api.prepare() first.
api.configure({ edits: { direction: 'reverse' }, format: 'gif', gifEdge: 240 });
const output = await api.export();
console.log(output.filename, output.byteSize);
// Set your browser automation download listener before this call:
api.download();
```

### Video to GIF

Upload the video. If preparation is required, call `prepare({ start: 0, end: 2, fps: 15, edge: 320 })` only when those times fit the source. Configure `{ format: 'gif', gifEdge: 0, gifFps: 15 }`, then export and download. When a small video opens automatically, use the trim frame range to select the desired section.

### Extract frames

Import media, configure the desired inclusive trim range, then `const zip = await api.extract('all')`. Save its Blob as a download or read bytes in the page. The UI alternative is `Download frames (ZIP)`; current PNG and selected ZIP controls are also available.

## UI-only automation

Use accessible labels and roles, never screen coordinates. Upload with `Choose source media`. Use `Direction`, `Format`, and exact numeric field labels. Wait for processing to finish. Choose GIF explicitly, click `Export GIF`, wait for `Download GIF`, then save the browser download. Numeric trim inputs and frame position selectors provide alternatives to dragging. Preserve the current URL during edits and tool handoffs. Validate downloaded file contents, not just the existence of a download button.
