Skip to content

[1.x] Support image masks for OpenAI image edits - #1260

Open
dwivedianuj9118 wants to merge 1 commit into
laravel:1.xfrom
dwivedianuj9118:openai-image-edit-mask
Open

dwivedianuj9118 wants to merge 1 commit into
laravel:1.xfrom
dwivedianuj9118:openai-image-edit-mask

Conversation

@dwivedianuj9118

Copy link
Copy Markdown
Contributor

Closes #880.

OpenAI's /v1/images/edits endpoint takes an optional mask file for inpainting, but every attachment is sent as image/image[] and provider options are sent as form fields, so there was no way to send one.

This takes a mask out of the provider options when editing and attaches it as the multipart mask file:

Image::of('Remove the selected object')
    ->attachments([Files\Image::fromStorage('source.png')])
    ->withProviderOptions(['mask' => Files\Image::fromStorage('mask.png')])
    ->generate('openai');

As discussed on the issue, this keeps the ImageGateway contract and the other image gateways unchanged. The mask is read the same way as the source images, so base64, remote, local, stored and uploaded images all work. A mask without an image to edit throws an InvalidArgumentException instead of being sent to the generations endpoint.

Tests cover the mask on gpt-image and dall-e-2 models, an unsupported mask type, and a mask without an attachment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mask support for OpenAI image edits

1 participant