ElBruno.Text2Image.Cpu
1.2.11
dotnet add package ElBruno.Text2Image.Cpu --version 1.2.11
NuGet\Install-Package ElBruno.Text2Image.Cpu -Version 1.2.11
<PackageReference Include="ElBruno.Text2Image.Cpu" Version="1.2.11" />
<PackageVersion Include="ElBruno.Text2Image.Cpu" Version="1.2.11" />
<PackageReference Include="ElBruno.Text2Image.Cpu" />
paket add ElBruno.Text2Image.Cpu --version 1.2.11
#r "nuget: ElBruno.Text2Image.Cpu, 1.2.11"
#:package ElBruno.Text2Image.Cpu@1.2.11
#addin nuget:?package=ElBruno.Text2Image.Cpu&version=1.2.11
#tool nuget:?package=ElBruno.Text2Image.Cpu&version=1.2.11
ElBruno.Text2Image
๐ฆ NuGet Packages
| Package | Version | Downloads |
|---|---|---|
| ElBruno.Text2Image | ||
| ElBruno.Text2Image.Foundry | ||
| ElBruno.Text2Image.Cpu | ||
| ElBruno.Text2Image.Cuda | ||
| ElBruno.Text2Image.DirectML | ||
| ElBruno.Text2Image.Cli |
๐ข Origin Story: 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.
What is This?
Text-to-image for .NET developers: use as library, CLI tool, or AI coding skill. Cloud (FLUX.2, MAI-Image-2, GPT-Image) + local ONNX (Stable Diffusion). No Python required.
Three Ways to Use It
| ๐งโ๐ป .NET Developer | โจ๏ธ CLI User | ๐ค AI Agent Developer |
|---|---|---|
| Install NuGet package | Install global tool | Add as GitHub Copilot / Claude Code skill |
dotnet add package ElBruno.Text2Image.Foundry |
dotnet tool install -g ElBruno.Text2Image.Cli |
t2i init to enable agent discovery |
| Jump to Quick Start โ | Jump to CLI โ | Jump to AI Integration โ |
Model Support
โ๏ธ Cloud Models (API-based, no GPU required)
| Model | Provider | Use Case |
|---|---|---|
| FLUX.2 Pro/Flex | Microsoft Foundry | Photorealistic + text-heavy design |
| MAI-Image-2 | Microsoft Foundry | High-quality generation |
| GPT-Image-1.5 | Azure OpenAI (DALL-E 3) | Creative & reliable |
| GPT-Image-2 | Azure OpenAI | Next-gen quality |
๐ฅ๏ธ Local Models (ONNX Runtime, works offline)
| Model | Resolution | Speed | Hardware |
|---|---|---|---|
| Stable Diffusion 1.5 | 512ร512 | 15-50 steps | CPU/CUDA/DirectML |
| SDXL Turbo | 512ร512 | 1-4 steps | CPU/CUDA/DirectML |
| SD 2.1 Base | 768ร768 | 15-50 steps | CPU/CUDA/DirectML |
| LCM Dreamshaper v7 | 512ร512 | 2-4 steps | CPU/CUDA/DirectML |
Why This Library?
โ
No Python โ Pure .NET, no environment setup headaches
โ
~30 MB footprint โ Lightweight compared to Python stacks
โ
Cross-platform โ Windows, Linux, macOS
โ
Auto GPU detection โ CUDA โ DirectML โ CPU fallback
โ
Unified interface โ Same API for cloud and local models
โ
Microsoft.Extensions.AI โ Implements IImageGenerator standard
What's Your Use Case?
Are you a...
| You are... | Start here |
|---|---|
| .NET library developer building apps? | Quick Start โ Install NuGet package |
| CLI user needing quick image generation? | CLI Tool โ Install t2i global tool |
| AI agent developer integrating with Copilot/Claude? | AI Agent Integration โ Run t2i init |
| DevOps/infra person setting up CI/CD? | GitHub Actions Workflow |
๐ ๏ธ 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
Note: All packages are released with matching versions for consistency. Use t2i doctor to verify your CLI version and configuration.
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, may take 3-4 minutes)
t2i --provider gpt-image-2 "a sci-fi space station in orbit" --timeout 300
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 packageinstallation - ๐ฏ Multi-target โ Supports .NET 8.0 and .NET 10.0
- ๐ Microsoft.Extensions.AI โ All generators implement
IImageGeneratorfrom 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.OnnxRuntimevsMicrosoft.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
- docs/architecture.md โ Package structure and pipeline diagrams
- docs/gpu-acceleration.md โ GPU setup (CUDA, DirectML, auto-detection)
- docs/flux2-setup-guide.md โ Microsoft Foundry FLUX.2 setup
- docs/mai-image-2-setup-guide.md โ Microsoft Foundry MAI-Image-2 setup
- docs/gpt-image-1p5-setup-guide.md โ Azure OpenAI GPT-Image-1.5 (DALL-E 3) setup
- docs/model-support.md โ Detailed model comparison
- docs/onnx-conversion-guide.md โ Step-by-step ONNX conversion guide
- docs/publishing.md โ NuGet publishing guide (Trusted Publishing / OIDC)
- docs/version-management.md โ Version bumping and unified versioning workflow
- docs/security.md โ Security considerations and hardening
- scripts/ โ Python conversion and upload scripts
๐ 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.
Related Projects
- ElBruno.HuggingFace.Downloader
- ElBruno.LocalEmbeddings
- ElBruno.VibeVoiceTTS
- ElBruno.QwenTTS
- ElBruno.PersonaPlex โ NVIDIA PersonaPlex-7B-v1 speech-to-speech model wrapper for C#
| Product | Versions 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. |
-
net10.0
- ElBruno.Text2Image (>= 1.2.11)
- Microsoft.ML.OnnxRuntime (>= 1.24.1)
-
net8.0
- ElBruno.Text2Image (>= 1.2.11)
- Microsoft.ML.OnnxRuntime (>= 1.24.1)
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.2.11 | 103 | 5/10/2026 |
| 1.2.10 | 89 | 5/10/2026 |
| 1.2.9 | 90 | 5/10/2026 |
| 1.2.8 | 98 | 5/10/2026 |
| 1.2.6 | 104 | 4/28/2026 |
| 1.2.5 | 92 | 4/28/2026 |
| 1.2.4 | 106 | 4/28/2026 |
| 1.2.3 | 99 | 4/28/2026 |
| 1.2.2 | 100 | 4/28/2026 |
| 1.2.1 | 97 | 4/24/2026 |
| 1.2.0 | 100 | 4/22/2026 |
| 0.17.0 | 89 | 4/24/2026 |
| 0.16.0 | 92 | 4/22/2026 |
| 0.15.0 | 80 | 4/22/2026 |
| 0.10.0 | 100 | 4/22/2026 |
| 0.9.2 | 93 | 4/22/2026 |
| 0.9.1 | 177 | 4/20/2026 |
| 0.9.0 | 90 | 4/19/2026 |
| 0.8.0 | 112 | 4/13/2026 |
| 0.7.0 | 104 | 4/12/2026 |