ElBruno.Text2Image.Foundry 0.16.0

dotnet add package ElBruno.Text2Image.Foundry --version 0.16.0
                    
NuGet\Install-Package ElBruno.Text2Image.Foundry -Version 0.16.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="ElBruno.Text2Image.Foundry" Version="0.16.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ElBruno.Text2Image.Foundry" Version="0.16.0" />
                    
Directory.Packages.props
<PackageReference Include="ElBruno.Text2Image.Foundry" />
                    
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 ElBruno.Text2Image.Foundry --version 0.16.0
                    
#r "nuget: ElBruno.Text2Image.Foundry, 0.16.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 ElBruno.Text2Image.Foundry@0.16.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=ElBruno.Text2Image.Foundry&version=0.16.0
                    
Install as a Cake Addin
#tool nuget:?package=ElBruno.Text2Image.Foundry&version=0.16.0
                    
Install as a Cake Tool

ElBruno.Text2Image

Banner generated with FLUX.2 Pro on Microsoft Foundry

NuGet NuGet NuGet NuGet NuGet Build Status License: MIT GitHub stars Twitter Follow

HuggingFace ONNX Models: SD 2.1 ONNX SDXL Turbo ONNX

๐Ÿ“ข This project started with FLUX.2 Flex on Microsoft Foundry โ€” a cloud-first approach to text-to-image generation with best-in-class text rendering. After wrapping that API, we thought: "Why not bring the same developer experience to local models too?" So we did. Now you can generate images from text prompts using cloud APIs or local Stable Diffusion models with ONNX Runtime โ€” all through the same clean .NET interface.

A .NET library for text-to-image generation โ€” cloud and local. Generate images from text prompts using Microsoft Foundry FLUX.2 or Stable Diffusion (ONNX Runtime) with automatic model downloads from HuggingFace. No Python needed. Just dotnet add package and go. ๐Ÿš€

๐Ÿ› ๏ธ Command-Line Tool

Install the cross-platform CLI:

dotnet tool install --global ElBruno.Text2Image.Cli

Update to the latest version:

dotnet tool update --global ElBruno.Text2Image.Cli

CLI Examples

Local Models (Stable Diffusion):

t2i config                                           # interactive setup
t2i "a robot painting a landscape"                  # generate with default local model
t2i --provider stable-diffusion-15 "sunset over mountains, oil painting style"

Cloud Models (Microsoft Foundry & Azure OpenAI):

# FLUX.2 Pro (photorealistic)
t2i --provider foundry-flux2 "a futuristic cityscape with neon lights"

# FLUX.2 Flex (optimized for text-heavy design)
t2i config set foundry-flux2.model FLUX.2-flex
t2i "a business card design with modern minimalist style"

# MAI-Image-2 (high-quality generation)
t2i --provider foundry-mai2 "a serene mountain landscape at sunrise"

# GPT-Image-1.5 (DALL-E 3 via Azure OpenAI)
t2i --provider azure-openai-gpt-image-15 "an impressionist painting of a garden"

# GPT-Image-2 (next-gen model)
t2i --provider gpt-image-2 "a sci-fi space station in orbit"

Model Configuration:

# View current configuration
t2i config show

# Set default provider for cloud generation
t2i config set provider foundry-flux2

# Set model variant
t2i config set foundry-mai2.model MAI-Image-2e
t2i config set foundry-flux2.model FLUX.2-flex

# Provide credentials
t2i config set foundry-flux2.endpoint "https://your-resource.services.ai.azure.com"
t2i config set foundry-flux2.apiKey "your-api-key"

See docs/cli-tool.md for the full guide.

Features

  • ๐ŸŽจ Text-to-Image โ€” Generate images from text prompts using Stable Diffusion, FLUX.2, GPT-Image-1.5, and more
  • ๐Ÿค– Multiple Models โ€” Stable Diffusion 1.5, LCM Dreamshaper, SDXL Turbo, SD 2.1, FLUX.2, MAI-Image-2, GPT-Image-1.5, GPT-Image-2
  • โ˜๏ธ Cloud APIs โ€” FLUX.2, MAI-Image-2 (Microsoft Foundry), GPT-Image-1.5, GPT-Image-2 (Azure OpenAI)
  • ๐Ÿ”ง ONNX Runtime โ€” Fast, cross-platform inference (CPU, CUDA, DirectML)
  • โšก Auto GPU Detection โ€” Automatically uses GPU if available (CUDA โ†’ DirectML โ†’ CPU)
  • ๐Ÿ“ฆ NuGet Package โ€” Simple dotnet add package installation
  • ๐ŸŽฏ Multi-target โ€” Supports .NET 8.0 and .NET 10.0
  • ๐Ÿ”Œ Microsoft.Extensions.AI โ€” All generators implement IImageGenerator from Microsoft.Extensions.AI
  • ๐ŸŒฑ Reproducible โ€” Seed-based generation for reproducible results

๐Ÿค– AI Agent Integration

The t2i CLI is now discoverable by GitHub Copilot and Claude Code as a native skill, enabling AI agents to generate images directly within your development workflow. Run t2i init to configure skill integration, which adds the necessary metadata to .github/skills/t2i/ or .claude/skills/t2i/ directories in your workspace. Once integrated, AI agents can autonomously invoke t2i for image generation tasks without manual configuration.

See docs/skill-integration.md for the complete setup guide.

Quick Start

Install

Choose the package matching your hardware:

# CPU (default โ€” works everywhere)
dotnet add package ElBruno.Text2Image.Cpu

# NVIDIA GPU (CUDA โ€” 4x faster)
dotnet add package ElBruno.Text2Image.Cuda

# DirectML (AMD/Intel/NVIDIA on Windows)
dotnet add package ElBruno.Text2Image.DirectML

# FLUX.2 cloud via Microsoft Foundry (no GPU needed)
dotnet add package ElBruno.Text2Image.Foundry

Note: These are mutually exclusive โ€” install only ONE, following the same pattern as Microsoft.ML.OnnxRuntime vs Microsoft.ML.OnnxRuntime.Gpu.

Basic Usage โ€” Local (Stable Diffusion 1.5)

using ElBruno.Text2Image;
using ElBruno.Text2Image.Models;

// Create a Stable Diffusion 1.5 generator (model downloads automatically on first use)
using var generator = new StableDiffusion15();

// Generate an image from a text prompt
var result = await generator.GenerateAsync("a beautiful sunset over a mountain lake, digital art");

// Save the generated image
await result.SaveAsync("output.png");
Console.WriteLine($"Generated in {result.InferenceTimeMs}ms (seed: {result.Seed})");

Basic Usage โ€” Cloud (FLUX.2 via Microsoft Foundry)

using ElBruno.Text2Image;
using ElBruno.Text2Image.Foundry;

// Create a FLUX.2 generator using Microsoft Foundry
// Default model is FLUX.2-pro (photorealistic image generation)
using var generator = new Flux2Generator(
    endpoint: "https://your-resource.services.ai.azure.com",
    apiKey: "your-api-key",
    modelName: "FLUX.2 Pro",       // display name
    modelId: "FLUX.2-pro");        // deployment/model name

// Generate an image โ€” same interface as local models
var result = await generator.GenerateAsync("a futuristic cityscape with neon lights, cyberpunk style");
await result.SaveAsync("flux2-output.png");

// Or use FLUX.2 Flex for text-heavy design:
using var flexGenerator = new Flux2Generator(endpoint, apiKey,
    modelName: "FLUX.2 Flex", modelId: "FLUX.2-flex");

Basic Usage โ€” Cloud (MAI-Image-2)

using ElBruno.Text2Image;
using ElBruno.Text2Image.Foundry;

// Create an MAI-Image-2 generator using Microsoft Foundry
// Default model is MAI-Image-2
using var generator = new MaiImage2Generator(
    endpoint: "https://your-resource.services.ai.azure.com",
    apiKey: "your-api-key",
    modelName: "MAI-Image-2",
    modelId: "MAI-Image-2");

var result = await generator.GenerateAsync("a futuristic cityscape with neon lights, cyberpunk style");
await result.SaveAsync("mai-image2-output.png");

// Or use MAI-Image-2e for alternative model:
using var maiE = new MaiImage2Generator(endpoint, apiKey,
    modelName: "MAI-Image-2e", modelId: "MAI-Image-2e");

Basic Usage โ€” Cloud (GPT-Image-1.5 via Azure OpenAI)

using ElBruno.Text2Image;
using ElBruno.Text2Image.Foundry;

// Create a GPT-Image-1.5 (DALL-E 3) generator using Azure OpenAI
using var generator = new GptImage1p5Generator(
    endpoint: "https://your-resource.openai.azure.com/",
    apiKey: "your-api-key",
    deploymentName: "gpt-image-15");

// Generate an image โ€” same interface as other providers
var result = await generator.GenerateAsync("a serene mountain landscape at sunset, oil painting style");
await result.SaveAsync("gpt-image-1p5-output.png");

// Request specific size (1024ร—1024, 1792ร—1024, or 1024ร—1792)
var landscape = await generator.GenerateAsync(
    "a panoramic view of a futuristic cityscape",
    new ImageGenerationOptions { Width = 1792, Height = 1024 });

With Custom Options

using var generator = new StableDiffusion15();

var result = await generator.GenerateAsync("a futuristic cityscape at night, neon lights",
    new ImageGenerationOptions
    {
        NumInferenceSteps = 20,  // More steps = better quality
        GuidanceScale = 7.5,     // Higher = follows prompt more closely
        Width = 512,
        Height = 512,
        Seed = 42,               // For reproducible results
        ExecutionProvider = ExecutionProvider.Cpu
    });

await result.SaveAsync("cityscape.png");

Microsoft.Extensions.AI Interface

All generators implement Microsoft.Extensions.AI.IImageGenerator, enabling a standard API:

using Microsoft.Extensions.AI;
using ElBruno.Text2Image.Models;

// Any generator can be used via the M.E.AI interface
using var sd15 = new StableDiffusion15();
IImageGenerator generator = sd15;

var request = new ImageGenerationRequest("a whimsical treehouse in a fantasy forest");
var options = new ImageGenerationOptions
{
    ImageSize = new System.Drawing.Size(512, 512),
    AdditionalProperties = new AdditionalPropertiesDictionary
    {
        ["num_inference_steps"] = 15,
        ["guidance_scale"] = 7.5,
        ["seed"] = 42
    }
};

var response = await generator.GenerateAsync(request, options);
var imageBytes = response.Contents.OfType<DataContent>().First().Data.ToArray();
await File.WriteAllBytesAsync("output.png", imageBytes);

Custom Model Directory

// Download and use models from a specific directory
using var generator = new StableDiffusion15(new ImageGenerationOptions
{
    ModelDirectory = @"D:\MyModels",
    NumInferenceSteps = 15
});

await generator.EnsureModelAvailableAsync();
var result = await generator.GenerateAsync("a serene lake");
await result.SaveAsync("output.png");

Dependency Injection

// Local model
services.AddStableDiffusion15(options =>
{
    options.NumInferenceSteps = 20;
    options.ModelDirectory = "/path/to/models";
});

// Cloud model (requires ElBruno.Text2Image.Foundry package)
services.AddFlux2Generator(
    endpoint: "https://your-resource.openai.azure.com",
    apiKey: "your-api-key",
    modelId: "FLUX.2-pro");

// MAI-Image-2 cloud model (requires ElBruno.Text2Image.Foundry package)
services.AddMaiImage2Generator(
    endpoint: "https://your-resource.services.ai.azure.com",
    apiKey: "your-api-key",
    modelId: "MAI-Image-2");

// Inject IImageGenerator anywhere
public class MyService(IImageGenerator generator)
{
    public async Task<byte[]> GenerateImage(string prompt)
    {
        var result = await generator.GenerateAsync(prompt);
        return result.ImageBytes;
    }
}

Supported Models

Local Models (ONNX Runtime)

Model Class ONNX Source Steps VRAM Status
Stable Diffusion 1.5 StableDiffusion15 onnx-community/stable-diffusion-v1-5-ONNX 15-50 ~4 GB โœ… Available
LCM Dreamshaper v7 LcmDreamshaperV7 TheyCallMeHex/LCM-Dreamshaper-V7-ONNX 2-4 ~4 GB โœ… Available
SDXL Turbo SdxlTurbo elbruno/sdxl-turbo-ONNX 1-4 ~8 GB โœ… Available
SD 2.1 Base StableDiffusion21 elbruno/stable-diffusion-2-1-ONNX 15-50 ~5 GB โœ… Available

Cloud Models (REST API)

| Model | Class | Provider | Quality | Status | |-------|-------|----------|---------|--------| | FLUX.2 Pro | Flux2Generator | Microsoft Foundry | Excellent | โœ… Default | | FLUX.2 Flex | Flux2Generator | Microsoft Foundry | Excellent | โœ… Available | | MAI-Image-2 | MaiImage2Generator | Microsoft Foundry | Excellent | โœ… Available | | GPT-Image-1.5 | GptImage1p5Generator | Azure OpenAI (DALL-E 3) | Excellent | โœ… Available | See docs/model-support.md for detailed model comparison.

Samples

Sample Description
scenario-01-simple Basic text-to-image generation with SD 1.5
scenario-02-custom-options Custom seeds, guidance scale, and steps
scenario-03-flux2-cloud FLUX.2 cloud API via Microsoft Foundry
scenario-04-lcm-fast Ultra-fast generation with LCM Dreamshaper (2-4 steps)
scenario-05-sd21 Stable Diffusion 2.1 at 768ร—768 native resolution
scenario-06-model-comparison Compare SD 1.5 vs LCM side-by-side
scenario-07-custom-model-directory Download models to a custom directory
scenario-08-meai-interface Use via Microsoft.Extensions.AI IImageGenerator
scenario-09-batch-generation Generate multiple images from a batch of prompts
scenario-10-progress-reporting Detailed download progress reporting with progress bar
scenario-11-gpu-diagnostics Show CPU vs GPU provider detection and diagnostics
scenario-13-mai-image2-cloud MAI-Image-2 cloud API via Microsoft Foundry
scenario-15-gpt-image-1p5-cloud GPT-Image-1.5 (DALL-E 3) cloud API via Azure OpenAI

Run a Sample

cd src/samples/scenario-01-simple
dotnet run

Documentation

๐Ÿ‘‹ About the Author

Hi! I'm ElBruno ๐Ÿงก, a passionate developer and content creator exploring AI, .NET, and modern development practices.

Made with โค๏ธ by ElBruno

If you like this project, consider following my work across platforms:

  • ๐Ÿ“ป Podcast: No Tienen Nombre โ€” Spanish-language episodes on AI, development, and tech culture
  • ๐Ÿ’ป Blog: ElBruno.com โ€” Deep dives on embeddings, RAG, .NET, and local AI
  • ๐Ÿ“บ YouTube: youtube.com/elbruno โ€” Demos, tutorials, and live coding
  • ๐Ÿ”— LinkedIn: @elbruno โ€” Professional updates and insights
  • ๐• Twitter: @elbruno โ€” Quick tips, releases, and tech news

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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 is compatible.  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
0.16.0 0 4/22/2026
0.15.0 0 4/22/2026
0.10.0 0 4/22/2026
0.9.2 0 4/22/2026
0.9.1 40 4/20/2026
0.9.0 38 4/19/2026
0.8.0 102 4/13/2026
0.7.0 91 4/12/2026
0.6.0 122 2/28/2026
0.5.3 100 2/27/2026
0.5.2-preview 96 2/26/2026