Skip to content

Davidmotson.imagen editing docs #7080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: davidmotson.imagen_editing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ internal constructor(
throw FirebaseAIException.from(e)
}

/**
* Generates an image, based on both a prompt, and input image, returning the result directly to
* the caller.
*
* @param prompt The input(s) given to the model as a prompt.
* @param config The editing config given to the model.
*/
public suspend fun editImage(
prompt: String,
config: ImagenEditingConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.ai.type

/** Represents the edit mode for this imagen editing config */
public class ImagenEditMode private constructor(internal val value: String) {

public companion object {
/**
* Inpainting insertion is an edit mode where you mask off an area of the image, and use the
* prompt to add new elements to the image.
*/
public val INPAINT_INSERTION: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_INSERTION")
/**
* Inpainting removal is an edit mode where you mask off an area of the image, and use the
* prompt to remove elements from the image.
*/
public val INPAINT_REMOVAL: ImagenEditMode = ImagenEditMode("EDIT_MODE_INPAINT_REMOVAL")
/**
* Outpainting is an edit mode where your mask is larger than the image, and expands the
* boundaries of the image by continuing the background. The prompt can guide this process.
*/
public val OUTPAINT: ImagenEditMode = ImagenEditMode("EDIT_MODE_OUTPAINT")
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.ai.type

import kotlinx.serialization.Serializable

/**
* Configuration parameters to use for imagen editing.
* @property image the base image to be edited.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo in the KDoc for editMode. It should be editing instead of edititing.

Suggested change
* @property image the base image to be edited.
* @property editMode specifies the editing mode for this request.

* @property editMode specifies the edititing mode for this request.
* @property mask the mask to specify which sections of the base image can be edited.
* @property maskDilation a percentage by which to shrink the mask to allow some edge blending.
* @property editSteps the number of intermediate steps for the edit to take.
*/
@PublicPreviewAPI
public class ImagenEditingConfig(
internal val image: ImagenInlineImage,
Expand All @@ -14,6 +38,18 @@ public class ImagenEditingConfig(
public fun builder(): Builder = Builder()
}

/**
* Builder for creating a [ImagenEditingConfig].
*
* Mainly intended for Java interop. Kotlin consumers should use [imagenEditingConfig] for a more
* idiomatic experience.
*
* @property image see [ImagenEditingConfig.image]
* @property editMode see [ImagenEditingConfig.editMode]
* @property mask see [ImagenEditingConfig.mask]
* @property maskDilation see [ImagenEditingConfig.maskDilation]
* @property editSteps see [ImagenEditingConfig.editSteps]
*/
public class Builder {
@JvmField public var image: ImagenInlineImage? = null
@JvmField public var editMode: ImagenEditMode? = null
Expand All @@ -33,6 +69,7 @@ public class ImagenEditingConfig(

public fun setEditSteps(editSteps: Int): Builder = apply { this.editSteps = editSteps }

/** Creates a new [ImagenEditingConfig] with the attached arguments */
public fun build(): ImagenEditingConfig {
if (image == null) {
throw IllegalStateException("ImagenEditingConfig must contain an image")
Expand Down Expand Up @@ -60,6 +97,19 @@ public class ImagenEditingConfig(
)
}

/**
* Helper method to construct a [ImagenEditingConfig] in a DSL-like manner.
*
* Example Usage:
* ```
* imagenEditingConfig {
* image = baseImage
* mask = imageMask
* editMode = ImagenEditMode.INPAINTING_REMOVAL

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The example usage contains a typo. ImagenEditMode.INPAINTING_REMOVAL should be ImagenEditMode.INPAINT_REMOVAL (missing 'G' in INPAINTING). This could lead to compilation errors or confusion for users trying to follow the example.

Suggested change
* editMode = ImagenEditMode.INPAINTING_REMOVAL
* editMode = ImagenEditMode.INPAINT_REMOVAL

* maskDilation = 0.05
* }
* ```
*/
@PublicPreviewAPI
public fun imagenEditingConfig(init: ImagenEditingConfig.Builder.() -> Unit): ImagenEditingConfig {
val builder = ImagenEditingConfig.builder()
Expand Down
Loading