Editing Images with Prompts and Masks
This lesson explains prompt-driven edits of whole images and mask-based edits of selected regions with GPT-image models, and how to build editing workflows that keep the parts that should not change.
Learning outcomes
After completing this lesson, you will be able to:
- Make prompt-driven modifications to an image.
- Restrict an edit to a region with an inpainting mask.
- Design an editing workflow that keeps every version.
Prompt-driven modifications
A prompt-driven edit passes the image and an instruction to images.edit, such as "Make it an evening scene with warm street lights" or "Change the jacket to dark green". The model regenerates the image according to the instruction and may change any part of it, although it tries to keep unmentioned elements. Prompt-driven edits suit global changes of style, lighting, season or colour scheme.
The reason unmentioned parts can change is that a prompt-driven edit generates a new image guided by the original, rather than altering selected pixels. The model has to infer from the instruction which elements should stay the same, so a request such as "make the jacket green" may also shift a face, the background or the text on a sign. Precise instructions reduce this ("change only the jacket colour to dark green; keep the person, pose, background and lighting unchanged"), and high input fidelity helps preserve faces and logos. When nothing outside a region may change, a mask is the reliable choice, because it tells the model exactly which pixels it may regenerate.
Inpainting with masks
Inpainting restricts the edit to a region. The application supplies a mask: a PNG image with the same dimensions as the source image and an alpha channel, in which fully transparent pixels mark the area to regenerate and opaque pixels mark the area to keep. The prompt describes the whole desired image or the content of the masked area.
result = aoai.images.edit(
model="image-gen",
image=open("living_room.png", "rb"),
mask=open("sofa_mask.png", "rb"), # transparent where the sofa is
prompt="A living room with a light grey linen three-seat sofa in place of the old sofa",
size="1536x1024",
)Masks are usually created from a user's selection in an editing interface or from a segmentation step. Because generative models treat the mask as guidance, edges may blend slightly beyond it, and results are reviewed before use.
The following diagram shows the three inputs of an inpainting request and its result.

Editing workflows
Real editing tasks rarely take a single call. A designer may change the lighting, then replace an object, then adjust a colour, and may want to return to an earlier step when an edit goes wrong. An editing workflow therefore treats each edit as a new version rather than overwriting the image. It keeps the original, each edit with its prompt, mask and settings, and the chosen result. This supports undo and side-by-side comparison, and it provides the provenance record that shows how a published image was produced.
Each step in the workflow uses the technique that suits its scope. The deciding question is whether the change affects the whole image or one region, and whether any part must remain exactly as it is. The following list shows the choice of technique by requirement.
- Change the whole image's style or lighting: prompt-driven edit.
- Replace or remove one object: inpainting with a mask over the object.
- Combine elements from several images: edit with several input images and a prompt.
- Keep faces or logos unchanged: high input fidelity, and keep them outside the mask.
Choose the editing technique
Replacing a product in a scene
A furniture company has an approved photo of a living room and wants versions showing each of five new armchairs in the same position. Everything else in the room must stay identical.
Create a mask that is transparent only over the existing armchair, and call images.edit five times with the room photo, the mask and a prompt (plus a reference image of each chair) describing the new armchair. A prompt-only edit risks changing the rest of the room.
Which pixels are regenerated when inpainting with a mask?
Show answer
The transparent pixels in the mask, which must be the same size as the image.
Exam Tips
Remember for the exam
- Inpainting: mask the same size as the image; transparent pixels are regenerated.
- Prompt-driven edits suit global changes; masks suit local changes.
- Keep the edit history with prompts and masks for undo and provenance.