DALL-E 3: Image Generation

DALLE-3 Image Generation

Images are a big part of what makes a great app experience. AI models allow rapid generation of highly personalized images as opposed to generic stock images, and their ability to follow complex instructions is evolving fast.

Consider we are building a personal journal app. With the OpenAI’s DALLE-3 Image Generation API, we can generate a unique, beautiful image for each journal entry. Besides the user prompt, the DALLE-3 API includes several additional fields:

Image Quality

Images can be generated in two resolutions - standard and HD. HD creates images with finer details and greater consistency across the image, but costs more.

let standardQuality: OpenAI.Image.Quality = .standard
let hdQuality: OpenAI.Image.Quality = .hd

Image Size

The size of the generated images. Must be 1024x1024, 1792x1024, or 1024x1792.

let squareImage: OpenAI.Image.Size = .w1024h1024
let wideImage: OpenAI.Image.Size = .w1792h1024
let tallImage: OpenAI.Image.Size = .w1024h1792

Image Style

The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images.

let vividStyle: OpenAI.Image.Style = .vivid
let naturalStyle: OpenAI.Image.Style = .natural

Generate an Image

After selecting the settings that best suit your app, you can call the DALLE-3 API using Preternatural as follows:

// user's journal entry for today. 
// Note that the imagePrompt should be less than 4000 characters. 
let imagePrompt = "Today was an unforgettable day in Japan, filled with awe and wonder at every turn. We began our journey in the bustling streets of Tokyo, where the neon lights and towering skyscrapers left us mesmerized. The serene beauty of the Meiji Shrine provided a stark contrast, offering a peaceful retreat amidst the city's chaos. We indulged in delicious sushi at a local restaurant, the flavors so fresh and vibrant. Later, we took a train to Kyoto, where the sight of the historic temples and the tranquil Arashiyama Bamboo Grove left us breathless. The day ended with a soothing dip in an onsen, the hot springs melting away all our fatigue. Japan's blend of modernity and tradition, coupled with its unparalleled hospitality, made this trip a truly magical experience."
 
let images = try await openAIClient.createImage(
    prompt: imagePrompt,
    quality: OpenAI.Image.Quality.standard,
    size: OpenAI.Image.Size.w1024h1024,
    style: OpenAI.Image.Style.vivid
 
if let imageURL = images.first?.url {
    return URL(string: imageURL)
}

Using AI for image generation offers immense potential for enhancing user experience. By integrating the DALLE-3 API into your app, you can offer personalized, high-quality images generated in real-time. However, as developers and designers of our apps, we will have absolutely no control and no knowledge of the type of image that DALLE-3 will generate. It is possible, for example, that the colors and styling across images will make the app looks incohesive.

© 2024 Preternatural AI, Inc.