E-commerce: product photos
On this page
Updated November 2, 2026 — image models.
gpt-image-1, the model this course was originally written for, was discontinued on October 23, 2026.gpt-image-1.5,gpt-image-1-mini, andchatgpt-image-latestwill be retired on December 1, 2026. Examples now usegpt-image-2.5-sunburst, which offers the highest precision for editing;gpt-image-2.5-flareis faster for standard generation. Both models also supportxhighandmaxquality settings. GPT Image models always return images in base64: theresponse_formatparameter used by older DALL·E models is no longer accepted and has been removed from the code. Source: Image generation (OpenAI).
E-commerce: product photos
AI image generation is transforming e-commerce visual production. A traditional photo shoot requires a studio, a photographer, a retoucher, and several weeks of scheduling, with budgets running into thousands of euros. GPT Image produces a professional product visual in seconds. This lesson shows you how to generate images that are commercially viable—meaning they meet the visual standards of a product listing page—rather than creating mere decorative illustrations.
Product photos on a white background
A white background is the gold standard for e-commerce. Marketplaces require it, and shoppers expect it when comparing items side by side. The challenge isn’t simply saying “white background”; it’s describing the lighting that makes the product legible. The prompt in the function below stacks five specific details that make all the difference: pure white background, softbox studio lighting, a soft shadow to avoid a crude cutout effect, a slightly high 3/4 angle to add volume, and a reference to the “Amazon / premium e-commerce” style to frame the result.
from openai import OpenAI
import base64
client = OpenAI()
def photo_produit_fond_blanc(description_produit: str, output: str):
"""Generate a product photo on a white background, e-commerce style."""
prompt = (
f"{description_produit}, "
"professional product photography on pure white background, "
"studio softbox lighting, soft shadow, "
"slightly high 3/4 angle, "
"maximum sharpness, high resolution, "
"Amazon / premium e-commerce style"
)
response = client.images.generate(
model="gpt-image-2.5-sunburst",
prompt=prompt,
size="1024x1024",
quality="high",
)
data = base64.b64decode(response.data[0].b64_json)
with open(output, "wb") as f:
f.write(data)
print(f"Product photo: {output}")
photo_produit_fond_blanc(
"Matte black wireless headphones, premium design, leather ear cushions",
"casque_fond_blanc.png"
)
Lifestyle photos
A white-background photo informs; a lifestyle photo creates desire. It shows the product in its context of use, letting the buyer project themselves into the scene. An insulated water bottle resting on a rock facing a mountain panorama isn’t selling brushed steel; it’s selling a hike. The prompt vocabulary therefore shifts completely—natural light instead of studio, light bokeh instead of maximum sharpness, off-center composition following the rule of thirds instead of a centered subject. The format also switches to landscape, since these visuals serve as product page banners or social media content.
from openai import OpenAI
import base64
client = OpenAI()
def photo_lifestyle(produit: str, contexte: str, output: str):
"""Generate a lifestyle photo of a product in context."""
prompt = (
f"{produit} used in a {contexte} context, "
"editorial lifestyle photography, natural light, "
"depth of field with light bokeh, "
"off-center composition rule of thirds, "
"aspirational mood, magazine style"
)
response = client.images.generate(
model="gpt-image-2.5-sunburst",
prompt=prompt,
size="1536x1024",
quality="high",
)
data = base64.b64decode(response.data[0].b64_json)
with open(output, "wb") as f:
f.write(data)
print(f"Lifestyle photo: {output}")
photo_lifestyle(
"Brushed stainless steel insulated water bottle",
"mountain hiking, resting on a rock with a panoramic view",
"gourde_lifestyle.png"
)
photo_lifestyle(
"Brown waxed canvas backpack",
"trendy coffee shop, resting on a wooden chair next to a laptop",
"sac_lifestyle.png"
)
Color variations of the same product
A sneaker model available in five colors requires five rigorously identical visuals, differing only in color: same angle, same shadow, same framing. The loop below does exactly that. It keeps a block of photographic directives strictly constant, varying only the color name. What would cost you half a day of studio time and retouching is handled here in a single script execution.
from openai import OpenAI
import base64
client = OpenAI()
produit_base = "High-top leather sneakers"
couleurs = [
("white", "white_sneakers.png"),
("black", "black_sneakers.png"),
("burgundy red", "bordeaux_sneakers.png"),
("navy blue", "navy_sneakers.png"),
("olive green", "olive_sneakers.png"),
]
for couleur, filename in couleurs:
prompt = (
f"{produit_base} in {couleur}, "
"product photography on white background, studio lighting, "
"front 3/4 view, soft cast shadow, "
"premium e-commerce site style, maximum sharpness"
)
response = client.images.generate(
model="gpt-image-2.5-sunburst",
prompt=prompt,
size="1024x1024",
quality="high",
)
data = base64.b64decode(response.data[0].b64_json)
with open(filename, "wb") as f:
f.write(data)
print(f"Color {couleur} → {filename}")
Multi-view pack
A serious product listing never relies on a single shot. Buyers want to see the object from the front, side, top, and three-quarter view before pulling out their card. The pack_vues_produit function industrializes this requirement by iterating through four angle descriptions and suffixing each filename predictably. This allows your back-office system to automatically attach them to the correct SKU later.
from openai import OpenAI
import base64
client = OpenAI()
def pack_vues_produit(description: str, prefix: str):
"""Generate a pack of 4 product views."""
vues = [
("front view, centered", "face"),
("left profile view, 90 degree angle", "profil"),
("top view, flat lay", "dessus"),
("3/4 view, slightly high angle", "3-4"),
]
for prompt_vue, suffix in vues:
prompt = (
f"{description}, {prompt_vue}, "
"pure white background, professional studio lighting, "
"maximum sharpness, e-commerce style"
)
response = client.images.generate(
model="gpt-image-2.5-sunburst",
prompt=prompt,
size="1024x1024",
quality="high",
)
path = f"{prefix}_{suffix}.png"
data = base64.b64decode(response.data[0].b64_json)
with open(path, "wb") as f:
f.write(data)
print(f"View {suffix} → {path}")
pack_vues_produit(
"Smartwatch with black silicone strap, round dial, OLED screen",
"montre"
)
Modifying the background of an existing photo
Do you already have a photo on a white background and want a lifestyle version without regenerating the product? images.edit() lets you do this, provided you reason in reverse: the mask protects the product and frees up everything else. The function below draws an opaque ellipse in the center—the preserved zone—and leaves the periphery transparent for the model to repaint. The call specifies in the prompt that the central product remains intact, reinforcing the expected behavior.
import base64
from openai import OpenAI
from PIL import Image, ImageDraw
client = OpenAI()
def changer_fond_produit(image_path: str, nouveau_fond: str, output: str):
"""
Replace the background of a product photo.
Assumes the product is centered in the image.
"""
source = Image.open(image_path)
w, h = source.size
mask = Image.new("RGBA", (w, h), (0, 0, 0, 0))
draw = ImageDraw.Draw(mask)
# Opaque zone in center = protected
margin_x, margin_y = w // 5, h // 5
draw.ellipse(
[margin_x, margin_y, w - margin_x, h - margin_y],
fill=(0, 0, 0, 255)
)
mask.save("temp_mask_fond.png")
response = client.images.edit(
model="gpt-image-2.5-sunburst",
image=open(image_path, "rb"),
mask=open("temp_mask_fond.png", "rb"),
prompt=f"Background: {nouveau_fond}, the product in the center remains intact"
)
with open(output, "wb") as f:
f.write(base64.b64decode(response.data[0].b64_json))
print(f"Background modified: {output}")
changer_fond_produit(
"casque_fond_blanc.png",
"minimalist light wood design desk, blurred green plant in background",
"casque_lifestyle_auto.png"
)
What generation does not guarantee
Four caveats are worth noting before plugging this into a production catalog. First is consistency: GPT Image does not guarantee that the same product will be identical from one generation to the next. A color variation run three days later might return with a slightly different sole. The workaround is to generate all variants of the same SKU in the same session, as the color loop does.
Second concerns text on the product itself. Logos and printed labels are rendered well, but you still need to proofread them. A cream jar whose brand name is missing a letter might pass the script’s eye, but it won’t pass the customer’s. The third caveat involves real dimensions, which the model ignores. If proportions matter—a 50 ml bottle that shouldn’t look like a 1-liter jar—specify them explicitly in the prompt. The fourth is methodological: AI accelerates production, but it doesn’t replace human validation. No visual should ever go live on a product page without being reviewed by a person.
To test the entire chain, choose a real or fictional product and write a script that generates its complete e-commerce pack: one white-background photo, two lifestyle photos in different contexts, and three color variations. You’ll then get a concrete sense of what a catalog of one hundred SKUs represents.