Skip to content

Latest commit

 

History

History
47 lines (37 loc) · 1.23 KB

File metadata and controls

47 lines (37 loc) · 1.23 KB

Edit Images

The image edits endpoint lets you:

Edit existing images
Generate new images using other images as a reference
Edit parts of an image by uploading an image and mask indicating which areas should be replaced (a process known as inpainting)

Create a new image using image references

You can use one or more images as a reference to generate a new image.

In this example, we'll use 4 input images to generate a new image of a gift basket containing the items in the reference images. Body Lotion Soap Incense Kit Bath Bomb Bath Gift Set Edit an image

import base64 from openai import OpenAI client = OpenAI()

prompt = """ Generate a photorealistic image of a gift basket on a white background labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures. """

result = client.images.edit( model="gpt-image-1", image=[ open("body-lotion.png", "rb"), open("bath-bomb.png", "rb"), open("incense-kit.png", "rb"), open("soap.png", "rb"), ], prompt=prompt )

image_base64 = result.data[0].b64_json image_bytes = base64.b64decode(image_base64)

Save the image to a file

with open("gift-basket.png", "wb") as f: f.write(image_bytes)