Docs

Portrait motion

One finished sprite in. Eyes and mouth a game can drive separately out.

See also: Movie sprite

source.png

animation.webp · 4.0 MB

7 min
from sprite to finished face states
$1.05
estimated, for five model calls

Giving a finished sprite a blink and a few mouth shapes by hand means cutting out the face, drawing each state to match the original line work, lining the drawings up, masking them, and checking that nothing else on the sprite moved. FX Games holds that as one graph. A vision model finds the face; an image model draws every state in one sheet so they match each other; each drawing is aligned to the original and outlined; a reviewer that did not draw them judges every combination; and the accepted patches go back on the full sprite with every other pixel left exactly as it was. What comes out is not a fixed animation: each eye and the mouth is its own patch at one fixed offset, so a game can blink, wink and talk independently, in any order and at any pace.

Try it

Use FX Games' portrait motion workflow (uv run python -m grida.fx plan portrait-motion) to add a blink and mouth shapes to 1this sprite. Plan it first and tell me what it may cost, then run it live with a ceiling of five dollars, show me the animation, and tell me which features were accepted.

+

Paste it into an agent that can use this repository, and attach your own files where the prompt refers to them.

Use it

Eye on the left
Eye on the right
Mouth

Each eye and the mouth is its own patch, and their outlines never overlap, so any mix is exact, a wink included. A game stacks them the same way. All 9 combinations the run rendered were rebuilt from these patches when this page was built, pixel for pixel.

From sprite to face states

The face, found
The face workspace
Every new state, in one sheet
Fitted onto the face
Back on the sprite

What you get

run-01173 files, 64.7 MB
NameSizeKind
render32.7 MBFolder, 36 files
animation.webp4.0 MBThe authored timeline, played at the sprite's full size
states28.5 MBAll nine eyes-and-mouth states, each a full-size PNG of the sprite
patches126 KBThe six patches a game layers: each eye and the mouth, per state
manifest.json9 KBWhat a game reads: the offset, the patches, the states and the timeline
crop1.5 MBThe face workspace and how it maps back to the sprite
portrait24.0 MBEach stage's decisions and pictures
locator3.2 MBWhere the face was found, and why
execution.json3 KBHow the run ended and what it cost
and 2 more folders and 3 more files the pipeline keeps for recovery and auditing

Where it works

Works well

  • One finished character image, with or without transparency
  • Faces with clearly drawn open eyes and a readable mouth
  • Full-body sprites: the face is found and cropped automatically
  • Faces large enough that their line work reads at the sprite's own size

Not expected to work

  • Full lip sync: this run has two mouth shapes, A and O, not a complete set of speech shapes
  • Faces too small to read: enlarging them does not add detail
  • Eyes with hair drawn across them: the outline may be refused
  • Head or body movement: only the eyes and mouth change

Good to know

  • A result can be partial. If the mouth is refused but the eyes pass, the original mouth stays and the blink still works.
  • The eyes were reviewed as a pair. Winking one eye composes exactly, but was not judged on its own.
  • It reviews still pictures. Watch the animation play before accepting it.
  • Pairs with Movie sprite: use the loop's first frame as the source, and the face states sit on the moving body.

What goes wrong by hand

By handIn the graphHow
Time goes into an eye hidden by hair, or a mouth that cannot be redrawn.A reviewer decides feature by feature what can change. Anything unsure keeps its original drawing.
A new drawing comes back slightly moved, and the face swims when it blinks.Each drawing is aligned to the original and refused if it needs more than a small shift, turn or change of scale.
An eye mask cuts into the hair that sits over it.The outline is refused when it would cut through hair in front of the eye.
A blink also changes the hair beside the eye.A reviewer that did not draw the states checks every combination for changes around the eyes and mouth.
Pixels outside the face change, or the sprite's edges shift.Every pixel outside the patches, and all of the transparency, is checked identical to the original.

Models and tools

GPT-6 AstraOpenRouterVision model and reviewer
GPT Image 2.5 SunburstOpenAIImage model

Run it yourself

The workflow takes one finished character image and gives it selectable facial drawings: a half blink, closed eyes and two mouth shapes, as the spec asks. With a face crop (the default) it finds the face, draws the states in one sheet on a square crop of it, and returns them at the original sprite's full size. The source supplies the rest state, all of its transparency, and every pixel outside the facial patches. It animates drawings on a fixed image; it does not make speech audio, infer phonemes, move a body or do IK. The contract holds the graph, what each step checks, and what a run costs.

Inputs

An inputs file names the picture and the spec:

portrait: character.png
spec: src/fx_games/workflows/portrait_motion/inputs/face-four-card.json
face_crop: true

The picture is a PNG, RGB or RGBA, at most 16383 pixels on a side; a full-body sprite on transparency is fine. Keep a source whose face reads at its own size: enlarging a small face does not add detail. The committed inputs/face-four-card.json declares a 1024×1024 face workspace and a sheet of four 512×512 cards: both eyes and the mouth, and an eight-second sample timeline. A face crop's workspace and grid are square. To animate an opaque portrait whole instead, set face_crop: false and use inputs/four-card.json, whose 1024×1536 canvas the picture must match exactly.

uv run python src/fx_games/workflows/portrait_motion/inputs/make_inputs.py DIR draws an original geometric character both ways, with the two inputs files, to try the plan with.

Plan, run, read

uv run python -m grida.fx plan portrait-motion --inputs face.yaml
uv run python -m grida.fx run portrait-motion --inputs face.yaml --live --max-usd 5
uv run python -m grida.fx inspect portrait-motion

The plan prices the run before anything is paid for. The usual accepted run makes five paid calls: the face box, the feature decision, one sheet edit, the outlines and the still review, about one US dollar in all. Each answer is held by a judge, and a malformed one is drawn again, six takes at most, which is why the plan's ceiling is far above a usual run. The structured calls go to openai/gpt-6-astra through OpenRouter, with high reasoning and high image detail, through OpenAI only; the sheet goes to OpenAI's Sunburst edit route. The routes: of the fx.yaml you run from may choose another route: one the route tables do not have for that capability is refused while planning, and a request the route cannot take is refused before anything is sent, for nothing.

Every paid answer is kept in FX's call cache by the request that made it, so running the same inputs again pays for nothing, and a run that stopped continues where it stopped.

Read the result

outputs/result.json says what was accepted:

StatusMeaning
completeEvery requested feature was admitted and passed the still review.
partialSome features could not move; they keep their original drawing, and the rest passed.
refusedA stage refused: refused_at names it (face, admission, registration, geometry or quality) and reason says why.

A wide-open mouth may be refused while both eyes give an accepted blink; selecting a mouth state then keeps the original mouth. An accepted face-crop run delivers animation.webp, states/, patches/ and manifest.json under outputs/. A patch's RGB already includes its edge blending and its binary alpha marks the pixels to replace: the manifest says patch_application: "replace_selected_rgb_preserve_original_alpha" and gives offset_xy. Keep the original sprite's alpha, and never resize or blend a patch a second time. The component's apply_offset_patch does exactly that:

import json
from pathlib import Path

from PIL import Image

from fx_games.components.portrait_motion import apply_offset_patch

outputs = Path("out/runs/portrait-motion/<run>/outputs")
manifest = json.loads((outputs / "manifest.json").read_text())
with Image.open(outputs / "states" / "rest--rest.png") as rest:
    frame = rest.convert("RGBA")
selected = {"eyes": "eyes_closed", "mouth": "rest"}
for item in manifest["patches"]:
    group = "mouth" if item["feature_id"] == "mouth" else "eyes"
    if item["state_id"] == selected[group]:
        with Image.open(outputs / "patches" / f"{item['key']}.png") as patch:
            frame = apply_offset_patch(frame, patch, manifest["offset_xy"])

Start each selection from the rest state and apply only that selection's patches. The review judges still pictures: results keep temporal_review: "not_performed" and publication_authorized: false, so watch the animation play before accepting it.