Generate and Edit Images
30-second answer
To generate an image, you send a prompt to a gpt-image deployment and choose the size, quality, number of images and output format. To edit an image, you send the picture, a prompt and, for a precise change, a mask: a PNG of the same size where the transparent area is the only part the model may change. The image comes back as base64, and a transparent background needs PNG.
Simulate it » No Azure account neededExam objective: 3.1.1 Implement a solution that generates images from text prompts and reference media. 3.1.3 Configure image-editing workflows, including inpainting, mask-based edits and prompt-driven modifications. 3.1.5 Select and apply appropriate generation and editing controls provided by the platform. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Open <strong>Build → Models + endpoints</strong> and deploy <strong>gpt-image-1</strong>. The deployment name is what your code sends as the model.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Open Build → Models + endpoints and deploy gpt-image-1. The deployment name is what your code sends as the model.
- In the Images playground write the prompt, then set the size, quality, number of images and output format. Subject, style, light and layout belong in the prompt.
- In code, gpt-image models return the picture as base64. There's no URL to download, so decode and save it.
- To change only the sky, upload the image and a mask. The mask is a PNG of the same size, and the transparent area is what the model may repaint.
- Keep the controls straight: size, quality, n, format, background and the mask. A guardrail on the deployment still checks every prompt.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Generate and edit an image
A gpt-image deployment turns a prompt into pixels. Choose a size (1024x1024, 1024x1536 or 1536x1024), a quality (low, medium, high) and a format (PNG or JPEG). To change only part of a picture, send the image plus a mask: a PNG of the same size where the transparent area is what the model may repaint.
🤔 What happens if…
Read this tour as text
- Generate and edit an image. A gpt-image deployment turns a prompt into pixels. Choose a size (1024x1024, 1024x1536 or 1536x1024), a quality (low, medium, high) and a format (PNG or JPEG). To change only part of a picture, send the image plus a mask: a PNG of the same size where the transparent area is what the model may repaint.
- Generate and remix a video. Sora 2 makes video as an asynchronous job: create, poll until it's done, then download. Pick 720x1280 or 1280x720 and 4, 8 or 12 seconds. An input reference image must match the video size, and faces in it are rejected. Remix changes a finished video with a short prompt, ideally one change at a time.
- Ask a model about a picture. A multimodal chat model such as gpt-4.1-mini reads images you send with the prompt. The prompt decides the result: a concise caption, a detailed one, alt text for accessibility, or an answer to a question that points to what is visible. Up to 10 images can go in one request, and detail (low, high, auto) trades cost for small text.
- Content Understanding turns media into fields. Azure Content Understanding in Foundry Tools runs an analyzer on an image or video and returns the same structured record every time. Start from prebuilt-imageSearch or prebuilt-videoSearch, or create a custom analyzer with fields that classify or generate. For video, segmentation splits the file into scenes with their own fields, key frames and transcript.
- Keep visual content safe. Images and video need gates too. A guardrail with image controls classifies hate, sexual, violence and self-harm content, and a custom analyzer can enforce your own visual policy (a competitor's logo, a missing watermark). Text inside a picture can be an indirect prompt injection: read it as data, scan it with Prompt Shields, and never let it grant a tool or an approval.
Priya Sweets needs fresh shop banners and a new sky in last week's shop photo. Deploy a gpt-image model, generate images with the right size, quality and format, edit with a mask, and see a guardrail stop an unsafe prompt.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
The design team needs fifty product backgrounds by Friday, and every edit redraws the whole picture.
😊 THE SOLUTION
Generate with a gpt-image deployment and use a mask so only the background changes.
- Blank page for every banner✓ Prompt with size, quality and format
- An edit changes the logo too✓ A mask: transparent where change is allowed
- A cut-out needs a clear background✓ PNG with background set to transparent
Start with a question
Priya Sweets has one good photo of the shop, but the sky is flat grey. Can the owner fix just the sky without hiring a designer?
Yes, and that’s a different job from asking for a brand new picture.
When you ask a model to generate, it starts from a blank canvas and paints what your words describe. When you ask it to edit, it starts from your photo and has to decide what to keep. A mask is how you tell it: change this part, leave the rest.
Explain it like I’m 10
The technical explanation
In Microsoft Foundry you deploy an image model such as gpt-image-1. Your code calls the images API with the deployment name in the model field.
Generate
import base64, os
from openai import OpenAI
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
token = get_bearer_token_provider(DefaultAzureCredential(), "https://ai.azure.com/.default")
client = OpenAI(base_url=os.environ["AZURE_OPENAI_ENDPOINT"].rstrip("/") + "/openai/v1/", api_key=token)
result = client.images.generate(
model="gpt-image-1", # your deployment name
prompt="Festival banner for Priya Sweets, laddoos on a brass tray, warm light",
size="1536x1024", quality="low", n=2,
output_format="png", background="auto",
)
for i, item in enumerate(result.data, 1):
open(f"banner_{i}.png", "wb").write(base64.b64decode(item.b64_json)) # base64 only
The controls you’re expected to know (checked on Microsoft Learn, 25 November 2026):
| Setting | Values | Notes |
|---|---|---|
size | 1024x1024, 1024x1536, 1536x1024 | Square, portrait, landscape |
quality | low, medium, high | Higher costs more and takes longer |
n | 1 to 10 | Images per request |
output_format | png, jpeg | No WEBP for output |
background | auto, transparent | Transparent needs PNG |
Edit with a mask
result = client.images.edit(
model="gpt-image-1",
image=open("shop-front.png", "rb"),
mask=open("mask.png", "rb"), # PNG, same size, transparent = may change
prompt="Replace the grey sky with a warm sunset. Keep everything else unchanged.",
input_fidelity="high", # keep faces, logos and text close to the original
)
An edit works in three ways. Mask-based (inpainting) changes only the transparent area. Prompt-driven edits send the image with no mask, and the model decides what to touch, which is fine for a style change but risky for exact details. You can also send reference images so a new picture borrows a product or a style.
What guardrails do here
A guardrail on the deployment checks the prompt, and unsafe requests are refused before any image is made. Generated images also carry content credentials, so people can see they came from AI. Both belong in your design, not in an afterthought.
Architect level Why does the same prompt give a different picture every time?
Image models sample, so a prompt is a brief, not a recipe. Put the subject, style, light and layout in the prompt, then use n to get several options. When one detail must be exact, such as a logo, don’t ask the model to draw it from memory. Supply it as a reference image or add it afterwards in your own code, and review the result.
Real-world business scenario
Priya Sweets
- The problem
- The marketing team made fifty festival banners by hand each year, and every photo edit risked changing the shop sign.
- What they used
- A gpt-image deployment in Foundry. Banners are generated at low quality for drafts, photos are edited with a mask, and the chosen draft is rendered again at high quality.
- Why that choice
- The mask keeps the sign and counters untouched, PNG gives clean logos, and the deployment's guardrail checks every prompt.
- The result
- The team reviewed ten drafts in the time it used to take to brief one, and no sign was altered by mistake.
When to use it and when not to
✓ Use it when…
- You need new marketing or concept images from a text brief.
- You must change one region of an existing image and keep the rest.
- You want several variations in a single request.
✕ Think twice when…
- You need an exact logo or legal text drawn perfectly. Place the real asset yourself.
- You need to read or classify photos you already have.
- The image could show a real person without their consent.
↔ Alternatives to consider
- A multimodal chat model to describe or question existing images.
- Content Understanding when every image needs the same fields.
Test yourself with exercises
5 original practice questions in the AI-103 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner How do you change only the sky in a photo with a gpt-image model?
Model answer
I call the image edit operation with the photo, a prompt that describes the new sky and a mask. The mask is a PNG the same size as the photo, and the sky area is transparent. Only that area can change.
Interviewer follows up
What if I leave the mask out?
You
Then the prompt is the only guide, and the model can redraw other parts too. I'd add the mask and set input fidelity to high.
Intermediate A designer wants a logo with no background. What do you set?
Model answer
I set the output format to PNG and the background to transparent. JPEG can't hold transparency, and WEBP isn't supported for output here.
Experienced developer How would you control cost for a banner tool that makes many variations?
Model answer
I'd use low quality for drafts and n up to 10 per request, and only render the chosen draft at high quality. I'd also set a token budget on the project and a guardrail on the deployment.
Scenario The app tries to read a URL from the response and gets nothing. Why?
Model answer
gpt-image models return base64 data only. I'd decode the b64_json value, save it as a file or upload it to Blob Storage, and share that link.
Quick revision
Key points
- Generation and edits use a gpt-image deployment, and your code sends the deployment name as the model.
- Sizes are 1024x1024, 1024x1536 and 1536x1024. Quality is low, medium or high. n is 1 to 10.
- Output format is PNG or JPEG. A transparent background needs PNG.
- A mask is a PNG of the same size, and transparent pixels are the area that can change.
- Images come back as base64. Guardrails check prompts, and generated images carry content credentials.
Important terminology
- gpt-image
- The family of Azure OpenAI image models, such as gpt-image-1, that generate and edit images from text prompts and reference images.
- Mask
- A PNG with the same dimensions as the image where transparent pixels mark the area an edit may change.
- Inpainting
- Repainting only a selected region of an existing image, usually with a mask and a prompt.
- Input fidelity
- An edit setting (low or high) that controls how closely the model keeps faces, logos and fine details from the input image.
- Content credentials
- Provenance metadata added to generated images so that others can tell they were made by AI.
Common mistakes
- Editing without a mask and expecting only one area to change.
- Using a mask with different dimensions from the image.
- Asking for WEBP output or a transparent background in JPEG.
Exam tips
- "Change only part of an image" = mask-based edit (transparent area).
- "Transparent background" = PNG output with background transparent.
- "Keep faces and logos close to the original" = input_fidelity high.
Five quick revision questions
-
1.What does the transparent area of a mask mean?Show
It is the area the model may change.
-
2.Which format gives a transparent background?Show
PNG.
-
3.How many images can one request create?Show
1 to 10, set with n.
-
4.In what form does gpt-image return the picture?Show
Base64 data, not a URL.
-
5.Which setting keeps faces and logos closer to the input?Show
input_fidelity set to high.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Generate and Edit Video
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.