How can I provide a RGBA png file to OpenAI PHP library

I import Orhanerday\OpenAi library to my DALL-E Examples project but when I provide images, I got Invalid input image - format must be in ['RGBA'], got RGB. error. I search for this error on the internet but I got nothing.

My code looks like

<?php

require __DIR__ . '/vendor/autoload.php'; // remove this line if you use a PHP Framework.

use Orhanerday\OpenAi\OpenAi;

$open_ai_key = getenv("OPENAIKEY");
$open_ai = new OpenAi($open_ai_key);
 
$otter = curl_file_create("C:\Users\dotor\OneDrive\Desktop\dalle-examples\otter.png");
$mask = curl_file_create("C:\Users\dotor\OneDrive\Desktop\dalle-examples\mask.png");

$result = $open_ai->imageEdit([
    "image" => $otter,
    "mask" => $mask,
    "prompt" => "A cute baby sea otter wearing a beret",
    "n" => 2,
    "size" => "256x256",
]);

var_dump($result);

Png files;

Otter => https://i.stack.imgur.com/oa6nv.png

Mask => https://i.stack.imgur.com/o4eqN.png

I need to get a result without any errors, what is an RGBA png file and how can I provide?

your code probably is okay, you need to use transparent png (RGBA - (RGB - alpha)).
I struggled to find a tool that can provide a sample image.

Here you can use my sample images
openai/OpenAI.Playground/SampleData
or you can use this website https://www.online-image-editor.com/ to get your RGBA image.

Note: Original image also has to be RGBA, seems unnecessary but it has to be.

1 Like

ImageMagick can be super useful if you need to convert images to RGBA or anything…

1 Like