Inpainting
Mark an area with a mask and repaint only that area; everything else stays as it was.
Not writing code? See Generate images in your own tools.
Before you start
https://api.ofox.io/v1openai/gpt-image-2.5-flarepip install openai pillowpillow is used to make the maskMask requirements
Illustration, not an actual generated result
- A PNG with an alpha channel. JPEG and opaque PNG do not work.
- Exactly the same size as the original image.
- Transparent pixels are repainted; opaque pixels keep the original.
- Only works on the edit endpoint. Sent to text to image, it is ignored.
Steps
Make a mask
Skip this step if you already have one.
This snippet reads input.png from the current directory, makes the middle 40% square transparent, and saves it as mask.png.
from PIL import Image, ImageDraw
src = Image.open("input.png")
mask = Image.new("RGBA", src.size, (0, 0, 0, 255)) # fully opaque = keep everything
w, h = src.size
ImageDraw.Draw(mask).rectangle( # transparent area = what gets repainted
(int(w * 0.3), int(h * 0.3), int(w * 0.7), int(h * 0.7)), fill=(0, 0, 0, 0)
)
mask.save("mask.png")Send the request
Every sample below was run verbatim. The result is saved as output.png in the current directory.
cURL
# mask.png: same size as input.png, with an alpha channel; transparent area = what gets repainted
curl -s https://api.ofox.io/v1/images/edits \
-H "Authorization: Bearer YOUR_OFOX_API_KEY" \
-F "model=openai/gpt-image-2.5-flare" \
-F "image=@input.png" \
-F "mask=@mask.png" \
-F "prompt=An orange cat sitting in the center, background and everything else unchanged" \
-F "quality=low" \
-o response.json
jq -r '.data[0].b64_json' response.json | base64 --decode > output.pngWriting the prompt
Describe the whole image as it should look afterwards, not just what to add.
Measured result
Outside the mask the image barely changes: the mean pixel difference from the original is under 2/255.
For comparison, editing the same image without a mask changed the same area by 120/255.
Troubleshooting
For other errors, see the full error table.
Official docs
OpenAI’s docs describe behavior when you call OpenAI directly. When you call through OfoxAI, the measured results in these pages take precedence. For example, you don’t need to pin a provider for editing.