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.

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 ๐Ÿ’ฌ๐Ÿพ

2 responses to “๐Ÿง โœจ Testing GPT-4oโ€™s Image Generation โ€“ From C# with โค๏ธ and Microsoft.Extensions.AI”

  1. […] ๐Ÿง โœจ Testing GPT-4oโ€™s Image Generation โ€“ From C# with โค๏ธ and Microsoft.Extensions.AI (Bruno Capuano) […]

    Like

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading