Image Operations

To integrate OpenAI's image generation, editing, and variation capabilities into your Unity project, you'll primarily interact with three types of requests using the OpenAI with unity asset. These requests are designed to leverage OpenAI's advanced image models, such as DALL·E, to create, modify, and generate variations of images based on textual prompts or existing images.

For a deep dive into the technical details and options available for these requests, refer to the Images API Reference.

Image Operations Overview:

  1. Image Creation: Generate new images from textual prompts.

  2. Image Editing: Modify existing images based on textual instructions.

  3. Image Variations: Create different variations of an input image.

Sample Code for Image Requests:

1. Image Creation Request:

Generate new images from a textual description using CreateTextures.

ImageCreationRequest request = new ImageCreationRequest.Builder()
    .SetPrompt("A futuristic city skyline at sunset")
    .SetN(2) // Number of images to generate
    .Build();

Texture2D[] textures = await request.ExecuteAsync();

// Now you can use these textures in your Unity project

2. Image Editing Request:

Edit an existing image based on a provided prompt. You'll need to supply the image as a FormFile (for API requests) or a Texture2D object (within Unity).

ImageEditRequest request = new ImageEditRequest.Builder()
    .SetImage(formFile or Texture2D) // The image you want to edit
    .SetPrompt("Add a dog sitting next to the person")
    .Build();

Texture2D[] editedTextures = await request.ExecuteAsync();

// Use the edited images in your project

3. Image Variation Request:

Generate variations of an input image. Similar to image editing, the image should be provided as a FormFile or Texture2D.

ImageVariationRequest request = new ImageVariationRequest.Builder()
    .SetImage(formFile or Texture2D) // Base image for variations
    .SetN(3) // Number of variations to generate
    .Build();

Texture2D[] variationTextures = await request.ExecuteAsync();

// Incorporate these variations into your Unity scene

These operations empower your Unity applications with dynamic visual content generation capabilities, directly interfacing with OpenAI's sophisticated image models. Whether creating new images from scratch, tweaking existing ones, or exploring variations, these tools unlock creative possibilities for game development, interactive media, and beyond.

Last updated