Reproduces the 5.2 Virtual Clothing Try-On example from the OpenAI cookbook Image generation models prompting guide.
Given a photo of a person and separate garment images, the model edits the photo to dress the person in those garments — keeping their face, body, pose, and the background unchanged, and altering only the clothing.
| Path | Description |
|---|---|
input_images/woman_in_museum.png |
Base photo — the person being dressed |
input_images/tank_top.png |
Garment: tank top |
input_images/jacket.png |
Garment: jacket |
input_images/boots.png |
Garment: boots |
virtual_tryon.py |
Runnable script that calls client.images.edit(...) |
output_images/ |
Created at runtime; the result lands here |
Input images were downloaded from the cookbook's source repo
(openai/openai-cookbook, images/input_images/).
pip install openai
export OPENAI_API_KEY=sk-... # PowerShell: $env:OPENAI_API_KEY="sk-..."
python virtual_tryon.pyResult is written to output_images/outfit_gpt-image-2.png.
- The garment
tank_top.pngis passed twice in theimage=[...]list, matching the cookbook. Repeating a reference reinforces it. - The script uses model
gpt-image-2as in the guide. If that model isn't enabled on your account, change it togpt-image-1invirtual_tryon.py. - The whole technique hinges on the prompt explicitly locking the invariants (identity, pose, background) and permitting change only to the clothing.