Edit endpoint returns original photo

I want to change an existing photo. My goal is to transform a selfie into a watercolor style picture.
I make a request using curl in the console. The request passes, but in the response I receive the URL to the original image, as if the space is completely empty. Has anyone had a similar problem? I tried different formats and photo resolutions, added a mask. All to no avail.
My request:

curl -H 'Authorization: Bearer sk-***uPb' https://api.openai.com/v1/images/edits --form 'image=@"./tmp/selfie.png"' --form 'prompt="replace background to river and use watercolor style for photo"' --form 'size="256x256"' --form 'n=1'
1 Like

The edits endpoint can only modify the image in areas where there is a 32-bit alpha layer that is completely transparent.

Here’s a 256px PNG that has the middle 1/3 as transparent. Click “download” or right-click and save and hopefully you’ll get a version that the forum hasn’t re-encoded, and then use that as your mask file to see if the transparent area is re-drawn.

maskbar

Edits won’t be able to redo the whole image as a watercolor (and variations takes no prompt).

2 Likes

Thank you, it is working.
But if I use mask file, which all emty-openai erase photo and I see only river. So is impossible to save person and change photo style?

1 Like

That is correct: Edits is infill and outfill into the transparent areas. If you try to use it as “everything-fill”, you just get a poor DALL-E 2 image based on the prompt.

I read the “Image Edit” and “Image Variation” APIs and it made sense kind of, but we sure could benefit from having some actual examples of use cases.

1 Like

Original image:

Marked transparent in image edit software, then saved as RGB+A 32-bit PNG.

Request:

from openai import OpenAI
client = OpenAI()

response = client.images.edit(
  image=open("with-mask.png", "rb"),
  prompt="A insect prince",
  response_format="url",  # or b64_json
  size="1024x1024"
  
)
print(response.data[0].url)

# your download code here, or save from base64 response

Result:

(Typical ignoring of prompt field…and quality less than straight DALL-E 2)

3 Likes

That’s a great example, thanks! The API documentation would really benefit from having some sample images like these, but people will likely find it here too, if they search this forum.

1 Like