Generate and edit images with GPT Image
In this cookbook, you'll learn how to use GPT Image, our new large language model with image generation capabilities.
Get this prompt chain
Generate and edit images with GPT Image
In this cookbook, you'll learn how to use GPT Image, our new large language model with image generation capabilities.
This model has world knowledge and can generate images leveraging this broad understanding of the world.
It is also much better at instruction following and producing photorealistic images compared to our previous-generation image models, DallE 2 and 3.
To learn more about image generation, refer to our guide.
Set up
Generate an image
GPT Image 1 is great at instruction-following, meaning you can prompt the model to generate images with very detailed instructions.
Customize the output
You can customize the following output properties:
- Quality can be
low,medium,highorauto(default value) - Size can be
1024x1024(square),1536x1024(portrait),1024x1536(landscape) orauto(default) - You can adjust the compression level (from 0-100%) for JPEG and WEBP formats
- You can choose to generate an image with a transparent background (only available for PNG or WEBP)
Transparent background
You can use the background property to request a transparent background, but if you include in your prompt that you want a transparent background, it will be set to transparent by default.
Edit images
GPT Image can also accept image inputs, and use them to create new images. You can also provide a mask if you don't want the model to change a specific part of the input image.
You can use a maximum of 10 input images, and if you use a mask, it will be applied to the first image provided in the image array.
Edit an image with a mask
You can also provide a mask along with your input images (if there are several, the mask will be applied on the first one) to edit only the part of the input image that is not covered by the mask. Please note that the model might still edit some parts of the image inside the mask, but it will avoid it.
Important note: the mask should contain an alpha channel. If you're generating it manually, for example using an image editing software, make sure you include this alpha channel.
Generating the mask
For this example, we'll use our model to generate the mask automatically for us. The mask might not be exact, but it will be enough for our purposes.
If you need to have an exact mask, feel free to use an image segmentation model.
Creating an alpha channel
This step is optional, if you want to turn a black & white image into a mask with an alpha channel that can be used in the Image Edit API.
Editing with the mask
When using a mask, we still need the prompt the model describing the entiring resulting image, not just the area that is masked.
Wrapping up
In this cookbook, we've seen how to use our new image generation model, GPT Image, to either generate new images from scratch, or use reference images. We've also covered how to create a mask with an alpha channel to apply it to an input image, to guide the image edition even further.
Feel free to use this as a starting point to explore other use cases, and if you're looking for some inspiration, check out the image gallery in our docs.
Happy building!