DEV Community

El Bruno
El Bruno

Posted on • Originally published at elbruno.com on

🧠✨ Testing GPT-4o’s Image Generation – From C# with ❤️ and Microsoft.Extensions.AI

Hi!

OpenAI just dropped some exciting news:

👉 GPT-4o can now generate images directly from prompts.

Announced here: Introducing GPT-4o Image Generation, this new feature lets you go from words to stunning visuals – including photorealistic scenes, illustrations, logos, and more.

The fun part? You can now generate images just by chatting with GPT-4o.

The challenging part? If you’re a developer trying this via the OpenAI API… it’s not quite ready yet 😅


🎯 My Test: “Make Me a Cute Sticker”

So, naturally, I tried this in ChatGPT — and it worked beautifully.

Just uploaded a photo of my cat, added this prompt:

“Make me a cute minimalist sticker based on the provided image. Use a thick white border and transparent background.”

Boom 🐾 — instant sticker! Minimalist lines, clear cat expression, perfect for printing or slapping on your laptop.


🔧 Now Let’s Try in C# (Spoiler: it’s not ready… yet)

Being a .NET fanboy and AI tinkerer, I fired up a quick console app using the awesome new Microsoft.Extensions.AI library — designed to unify and simplify AI model calls from .NET.

Here’s my code using the OpenAIClient with GPT-4o:

using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using OpenAI;
using System.Reflection;
// 1. get the image
var imageLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "images", "petsmusic.png");
var mediaType = GetMediaType(imageLocation);
byte[] imageBytes = File.ReadAllBytes(imageLocation);
// 2. prep openai client using gpt-4o
var imageGenPrompt = $"make me a cute minimalist sticker based on the provided image. use a thick white border and transparent background.";
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
IChatClient chatClient = new OpenAIClient(config["OPENAI_APIKEY"]).AsChatClient("gpt-4o");
List<ChatMessage> messages =
[
new ChatMessage(ChatRole.User, imageGenPrompt),
new ChatMessage(ChatRole.User, [new DataContent(imageBytes, mediaType)]),
];
// 3 run image generation
var imageAnalysis = await chatClient.GetResponseAsync(messages);
Console.WriteLine($"Prompt: {imageGenPrompt}");
Console.WriteLine();
Console.WriteLine($"Response: {imageAnalysis.Text}");
Console.WriteLine();
static string GetMediaType(string imageLocation)
{
// Logic to determine the media type based on the file extension
string extension = Path.GetExtension(imageLocation).ToLower();
return extension switch
{
".jpg" or ".jpeg" => "image/jpeg",
".png" => "image/png",
".gif" => "image/gif",
_ => throw new NotSupportedException($"File extension {extension} is not supported"),
};
}

📉 The Actual Output

Here’s what I got back from GPT-4o via API:


Prompt: make me a cute minimalist sticker based on the provided image...

Response:
To create a cute minimalist sticker from the provided image, follow these steps:
1. Crop and Simplify...
2. Add a thick white border...
3. Use a transparent background...

You can use tools like Adobe Illustrator or Canva.

Enter fullscreen mode Exit fullscreen mode

Basically — the model understood the task, but instead of returning a new image, it gave instructions 📄.


❗ Why the Disconnect?

The image generation capability is live in ChatGPT, but not yet exposed via the OpenAI API.

As of now:

  • GetResponseAsync() from Microsoft.Extensions.AI supports image inputs ✅
  • But image generation as an output is not yet supported ❌

So developers: sit tight, it’s coming.


💡 Takeaways

  • GPT-4o’s new image generation is 🔥 — in ChatGPT.
  • If you’re building with .NET and Microsoft.Extensions.AI, you’re already in a great spot to tap into these APIs as soon as image outputs are supported.
  • Until then, your code can analyze and interpret images with GPT-4o, but it can’t yet generate them.

👀 What’s Next?

I’m keeping this code snippet ready for when OpenAI opens up the feature.

And I’m already thinking about using this in:

  • Sticker generators 🐱
  • Avatar creators 🧙
  • Meme bots 🤖
  • Or even something weird, like “What if your plant could draw?”

Let me know if you want to explore this together — or if you’re building cool stuff with GPT-4o and .NET.

Until then, happy coding!

— Bruno 💬 🐾

Top comments (0)