> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bfl.ml/llms.txt
> Use this file to discover all available pages before exploring further.

# Edit and control with FLUX 3.1 Image

> Steer edits in FLUX 3.1 Image with written instructions, painted black-and-white masks, up to 10 reference images, and bounding boxes.

FLUX 3.1 Image

# Edit and control

FLUX 3.1 Image supports multiple ways to edit and guide outputs, from written instructions and painted masks to multi-reference inputs and bounding boxes.

Examples below use the [`generate()` helper](https://docs.bfl.ml/flux_3_1/flux31_image_overview#quickstart). Set `resolution` and `aspect_ratio` to `match_first_image` to keep the input image's dimensions.

## Choosing an edit control

| Control | Best for | Pixel preservation |
| - | - | - |
| [Instruction edit](#instruction-edits) (no mask) | Replacing, adding, or restyling objects—especially when the new subject, shadows, or reflections extend past the original silhouette | Local edits at `match_first_image` automatically preserve untouched areas without clipping overhangs or cast shadows |
| [Bounding boxes](https://docs.bfl.ml/flux_3_1/flux31_image_bounding_boxes.md) (`bounding_boxes`) | Controlling where objects are placed, moved, resized, or removed while letting lighting and shadows adapt naturally | Guides placement without a hard pixel lock |
| [Painted mask](#painted-masks) (`mask`) | Strict pixel lock outside a fixed boundary (compositing verbatim pixels from `images[0]`) | Black (`0`) is locked pixel-identically to `images[0]`; white (`255`) can change; gray linearly alpha-blends original and edited pixels |

## Painted masks

Pass a black-and-white `mask` matching the aspect ratio of `images[0]` when you need pixels outside a fixed boundary locked identically to `images[0]`. White marks what can change, black is composited verbatim from `images[0]`, and gray values linearly alpha-blend original and edited pixels.

Leave enough white padding for larger replacements, cast shadows, and reflections, and keep gray to narrow edge feathering—wide gray transition bands alpha-blend original and edited pixels and will ghost overhanging changes. If the new object or its shadow needs room to grow outside the old object's footprint, use an [unmasked instruction edit](#instruction-edits) or [bounding boxes](https://docs.bfl.ml/flux_3_1/flux31_image_bounding_boxes.md) instead.

Pass a hosted mask URL directly into `mask` (or base64 PNG):

```python Python theme={null}
generate({
    "prompt": "Inside the painted mask on the red-brick wall, paint a bold modern geometric street mural in vibrant cobalt blue, warm ochre yellow, terracotta, and cream abstract curved shapes with matte brick-textured paint following the real mortar grooves. No text. Keep the bicycle, sidewalk, shadows, and all brick outside the mask completely unchanged.",
    "images": ["https://cdn.sanity.io/images/2gpum2i6/production/0aad450d25e80dad6b378c112a0d03d1c9871b9e-1732x1154.webp"],
    "mask": "https://cdn.sanity.io/images/2gpum2i6/production/687f38e5809923bb5e69e80948030d3e9785c7fb-1732x1154.png",
    "resolution": "match_first_image",
    "aspect_ratio": "match_first_image",
}, name="brick_mural")
```

> [accordion] No mask file yet? Build a mask PNG in Python (Pillow)
>
> ```python Python theme={null}
> import base64
> from io import BytesIO
> import requests
> from PIL import Image, ImageDraw
>
> src_url = "https://cdn.sanity.io/images/2gpum2i6/production/0aad450d25e80dad6b378c112a0d03d1c9871b9e-1732x1154.webp"
> src_bytes = requests.get(src_url, timeout=60).content
> with Image.open(BytesIO(src_bytes)) as src:
>     w, h = src.size
>     mask = Image.new("L", (w, h), 0)  # black = keep
>     draw = ImageDraw.Draw(mask)
>     pts = [
>         (int(0.08 * w), int(0.72 * h)), (int(0.06 * w), int(0.42 * h)),
>         (int(0.14 * w), int(0.20 * h)), (int(0.32 * w), int(0.11 * h)),
>         (int(0.56 * w), int(0.12 * h)), (int(0.78 * w), int(0.19 * h)),
>         (int(0.88 * w), int(0.34 * h)), (int(0.84 * w), int(0.49 * h)),
>         (int(0.64 * w), int(0.47 * h)), (int(0.48 * w), int(0.55 * h)),
>         (int(0.44 * w), int(0.75 * h)), (int(0.26 * w), int(0.80 * h)),
>     ]
>     draw.polygon(pts, fill=255)  # white = edit
>
> buf = BytesIO()
> mask.save(buf, format="PNG")
> mask_b64 = "data:image/png;base64," + base64.b64encode(buf.getvalue()).decode("ascii")
>
> generate({
>     "prompt": "Inside the painted mask on the red-brick wall, paint a bold modern geometric street mural in vibrant cobalt blue, warm ochre yellow, terracotta, and cream abstract curved shapes with matte brick-textured paint following the real mortar grooves. No text. Keep the bicycle, sidewalk, shadows, and all brick outside the mask completely unchanged.",
>     "images": [src_url],
>     "mask": mask_b64,
>     "resolution": "match_first_image",
>     "aspect_ratio": "match_first_image",
> }, name="brick_mural")
> ```

## Multi-reference

Send up to 10 images in `images` and refer to them in your prompt as `image 1`, `image 2`, and so on.

Put your main scene first so `aspect_ratio: "auto"` or `"match_first_image"` inherits its framing.

## Instruction edits

Pass `images` with a direct written instruction to restyle an image, wrap artwork onto a product, or update text and weather. For local changes, name both what changes and what stays fixed:

## Keep exploring

> [card] [Bounding boxes](https://docs.bfl.ml/flux_3_1/flux31_image_bounding_boxes.md)
>
> Draw boxes in Box Studio and run chained layout-to-edit workflows.

> [card] [API reference](https://docs.bfl.ml/api-reference/utility/generate-an-image-with-flux-3-1.md)
>
> Full request schema, field constraints, and response codes.

> [card] [Overview](https://docs.bfl.ml/flux_3_1/flux31_image_overview.md)
>
> Quickstart client, sizing options, 4K zoom inspector, and web grounding.

> [card] [Editing prompting guide](https://docs.bfl.ml/guides/prompting_editing_overview.md)
>
> Prompt patterns for single-reference and multi-reference edits.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.