ImageGenAi 1.0.0

dotnet add package ImageGenAi --version 1.0.0
                    
NuGet\Install-Package ImageGenAi -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ImageGenAi" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ImageGenAi" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ImageGenAi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ImageGenAi --version 1.0.0
                    
#r "nuget: ImageGenAi, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ImageGenAi@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ImageGenAi&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ImageGenAi&version=1.0.0
                    
Install as a Cake Tool

ImageGenAi 🖼️

AI-Powered Image Editing for .NET Developers

Transform and create images with OpenAI's new gpt-image-1 model. Generate, edit, and enhance images using simple C# code. Perfect for web apps, APIs, and automation tools.

When creating high quality and high fidelity images the API can take up to 60+ seconds to respond

NuGet License: MIT .NET

✨ Examples In The Demo Web Project

  • Remove backgrounds from product photos instantly
  • Change backgrounds to any scene or environment
  • Add logos/watermarks with perfect positioning
  • Enhance product photos with professional lighting and details
  • Create images from text descriptions

Your imagination is the limit!

🚀 Quick Start

1. Install the Package

dotnet add package ImageGenAi

2. Configure Your App

Important: You need to make sure your API key has access to the gpt-image-1 model or this will fail. Get your API key from https://platform.openai.com/api-keys

// In Program.cs
using ImageGen.Configuration;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddImageGenClient(options =>
{
    options.ApiKey = builder.Configuration["OPENAI_API_KEY"]!;
    // Api key from appsettings.json
});

var app = builder.Build();

3. Quick Stream Examples

Some examples of how to get an image stream into ImageGen.

From a file on disk:

using var fileStream = new FileStream("path/to/image.jpg", FileMode.Open);

From an uploaded file (ASP.NET Core):

// In your controller or page handler
public async Task<IActionResult> UploadImage(IFormFile uploadedFile)
{
    using var stream = uploadedFile.OpenReadStream();
    // Now use the stream with ImageGen
}

From a URL:

using var httpClient = new HttpClient();
using var stream = await httpClient.GetStreamAsync("https://example.com/image.jpg");

From a byte array:

var imageBytes = File.ReadAllBytes("path/to/image.jpg");
using var stream = new MemoryStream(imageBytes);

4. Use It!

using ImageGen.Core;
using ImageGen.Models;

// Inject the client
public class ImageService(IImageGenClient client)
{
    public async Task<byte[]> RemoveBackground(Stream imageStream)
    {
        var result = await client.EditAsync(new EditRequest(
            PrimaryImage: imageStream,
            Prompt: "Remove the background completely",
            InputFidelity: InputFidelity.High
        ));

        return result.Bytes.ToArray();
    }
}

📝 Code Examples

Remove Background

public async Task<byte[]> RemoveBackground(Stream imageStream)
{
    var result = await client.EditAsync(new EditRequest(
        PrimaryImage: imageStream,
        Prompt: "Remove the background, make it transparent",
        InputFidelity: InputFidelity.High, // Keeps details crisp
        Format: ImageFormat.Png
    ));

    return result.Bytes.ToArray();
}

Change Product Background

public async Task<byte[]> ChangeBackground(Stream productImage)
{
    var result = await client.EditAsync(new EditRequest(
        PrimaryImage: productImage,
        Prompt: "Place this product on a luxury marble background",
        InputFidelity: InputFidelity.High,
        Quality: ImageQuality.High
    ));

    return result.Bytes.ToArray();
}

Add Logo to Image

public async Task<byte[]> AddLogo(Stream mainImage, Stream logoImage)
{
    var result = await client.EditAsync(new EditRequest(
        PrimaryImage: mainImage,
        SecondaryImages: new[] { logoImage },
        Prompt: "Add the logo in the bottom right corner, blend naturally",
        InputFidelity: InputFidelity.High
    ));

    return result.Bytes.ToArray();
}

Generate Images from Text

public async Task<byte[]> GenerateImage(string description)
{
    var result = await client.GenerateAsync(new GenerateRequest(
        Prompt: $"Professional product photo: {description}",
        Width: 1024,
        Height: 1024,
        Quality: ImageQuality.High,
        Format: ImageFormat.Png
    ));

    return result.Bytes.ToArray();
}

💾 Saving Images to Disk

To save images to disk, simply write the bytes to a file:

// Save any result to disk
await File.WriteAllBytesAsync("output.png", result.Bytes.ToArray());

// Or with automatic file extension based on format
var extension = result.Format switch {
    ImageFormat.Png => "png",
    ImageFormat.Jpeg => "jpg",
    ImageFormat.Webp => "webp"
};
await File.WriteAllBytesAsync($"output.{extension}", result.Bytes.ToArray());

🎯 Key Features

  • High-Fidelity Editing: InputFidelity.High preserves faces, logos, and details
  • Simple & Clean: Easy-to-understand API designed for developers
  • Async First: Built for modern .NET with async/await
  • Type Safe: Strong typing prevents runtime errors
  • Production Ready: Handles errors gracefully and logs important events

🛠️ API Overview

Main Methods

  • GenerateAsync() - Create images from text prompts
  • EditAsync() - Edit existing images with prompts

🖥️ Try the Demo

Want to see it in action? Check out the simple web demo:

  • Remove backgrounds - Upload an image and make the background transparent or white
  • Add logos - Place logos on images with perfect positioning
  • Change backgrounds - Replace image backgrounds with new scenes
  • Enhance products - Improve product photos with better details

Each example shows you the exact AI prompt being used, so you can learn and adapt them for your own projects!

📚 Learn More

  • Full API Documentation: Check the XML comments in the code
  • Error Handling: See ImageGenException, RateLimitExceededException
  • Best Practices: Always use InputFidelity.High for important edits

📄 License

MIT License - see LICENSE file for details.


Ready to supercharge your .NET apps with AI image editing? 🚀

Start with the demo app, then integrate ImageGenAI into your project today!

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 256 9/16/2025