> ## Documentation Index
> This page is part of the Image and Video APIs product. Fetch the complete documentation index for Image and Video APIs at: https://cloudinary.com/documentation/llms-image-and-video-apis.txt?referrer=docpage and then use it to discover all relevant pages before exploring further.
> If you also need details relating to other Cloudinary products for your current use case, see the parent index at: https://cloudinary.com/documentation/llms.txt?referrer=docpage

# Generative replace


Use generative AI to replace objects in images with other objects.

Visualize product and design variations directly in context, such as different furniture in a room, an alternative outfit on a model, or a different item on a shelf, all from one base image. Marketing and merchandising teams can explore concepts quickly, without commissioning new photography for every idea.

> **See also**:
>
> Explore the complete syntax and all options for this effect, or try it out on your own images in the Console:

> * **See full syntax**: [e_gen_replace](transformation_reference#e_gen_replace) in the _Transformation Reference_

> * **Try it out**: [Generative replace](https://console.cloudinary.com/app/image/playground/generative-replace?media=image&collection=apparel&sample=me%2Freplace-apparel-1&from=sweater&to=leather+jacket+with+pockets&preserveGeometry=false&detectMultiple=false)

## Generative replace overview

Use natural language to describe what you want to replace in the image, and what to replace it with. 

For example, replace "the picture" with "a mirror with a silver frame" (`e_gen_replace:from_the%20picture;to_a%20mirror%20with%20a%20silver%20frame`): 

![Picture replaced with windows](https://res.cloudinary.com/demo/image/upload/e_gen_replace:from_the%20picture;to_a%20mirror%20with%20a%20silver%20frame/docs/chair.jpg "with_image:false")

```nodejs
cloudinary.image("docs/chair.jpg", {effect: "gen_replace:from_the picture;to_a mirror with a silver frame"})
```

```react
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/chair.jpg").effect(
  generativeReplace().from("the picture").to("a mirror with a silver frame")
);
```

```vue
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/chair.jpg").effect(
  generativeReplace().from("the picture").to("a mirror with a silver frame")
);
```

```angular
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/chair.jpg").effect(
  generativeReplace().from("the picture").to("a mirror with a silver frame")
);
```

```js
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/chair.jpg").effect(
  generativeReplace().from("the picture").to("a mirror with a silver frame")
);
```

```python
CloudinaryImage("docs/chair.jpg").image(effect="gen_replace:from_the picture;to_a mirror with a silver frame")
```

```php
use Cloudinary\Transformation\Effect;

(new ImageTag('docs/chair.jpg'))
	->effect(Effect::generativeReplace()->from("the picture")
->to("a mirror with a silver frame"));
```

```java
cloudinary.url().transformation(new Transformation().effect("gen_replace:from_the picture;to_a mirror with a silver frame")).imageTag("docs/chair.jpg");
```

```ruby
cl_image_tag("docs/chair.jpg", effect: "gen_replace:from_the picture;to_a mirror with a silver frame")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("gen_replace:from_the picture;to_a mirror with a silver frame")).BuildImageTag("docs/chair.jpg")
```

```dart
cloudinary.image('docs/chair.jpg').transformation(Transformation()
	.effect(Effect.generativeReplace().from("the picture")
.to("a mirror with a silver frame")));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("gen_replace:from_the picture;to_a mirror with a silver frame")).generate("docs/chair.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().effect("gen_replace:from_the picture;to_a mirror with a silver frame")).generate("docs/chair.jpg");
```

```flutter
cloudinary.image('docs/chair.jpg').transformation(Transformation()
	.effect(Effect.generativeReplace().from("the picture")
.to("a mirror with a silver frame")));
```

```kotlin
cloudinary.image {
	publicId("docs/chair.jpg")
	 effect(Effect.generativeReplace() { from("the picture")
 to("a mirror with a silver frame") }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/chair.jpg", {effect: "gen_replace:from_the picture;to_a mirror with a silver frame"})
```

```react_native
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/chair.jpg").effect(
  generativeReplace().from("the picture").to("a mirror with a silver frame")
);
```

Original image

Picture replacedwith mirror

## Preserve the shape of the object

If you want to maintain the shape of the object you're replacing, set the `preserve-geometry` parameter to `true`. For example, below, notice the difference between the position of the sleeves and neckline of the sweater, with and without preserving the geometry when the shirt is replaced with a cable knit sweater:

![Woman with shirt replaced by sweater, preserving geometry](https://res.cloudinary.com/demo/image/upload/e_gen_replace:from_shirt;to_cable%20knit%20sweater;preserve-geometry_true/docs/woman-in-shirt.jpg "with_image:false")

```nodejs
cloudinary.image("docs/woman-in-shirt.jpg", {effect: "gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true"})
```

```react
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-in-shirt.jpg").effect(
  generativeReplace().from("shirt").to("cable knit sweater").preserveGeometry()
);
```

```vue
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-in-shirt.jpg").effect(
  generativeReplace().from("shirt").to("cable knit sweater").preserveGeometry()
);
```

```angular
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-in-shirt.jpg").effect(
  generativeReplace().from("shirt").to("cable knit sweater").preserveGeometry()
);
```

```js
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-in-shirt.jpg").effect(
  generativeReplace().from("shirt").to("cable knit sweater").preserveGeometry()
);
```

```python
CloudinaryImage("docs/woman-in-shirt.jpg").image(effect="gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_True")
```

```php
use Cloudinary\Transformation\Effect;

(new ImageTag('docs/woman-in-shirt.jpg'))
	->effect(Effect::generativeReplace()->from("shirt")
->to("cable knit sweater")
->preserveGeometry());
```

```java
cloudinary.url().transformation(new Transformation().effect("gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true")).imageTag("docs/woman-in-shirt.jpg");
```

```ruby
cl_image_tag("docs/woman-in-shirt.jpg", effect: "gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true")).BuildImageTag("docs/woman-in-shirt.jpg")
```

```dart
cloudinary.image('docs/woman-in-shirt.jpg').transformation(Transformation()
	.effect(Effect.generativeReplace().from("shirt")
.to("cable knit sweater")
.preserveGeometry()));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true")).generate("docs/woman-in-shirt.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().effect("gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true")).generate("docs/woman-in-shirt.jpg");
```

```flutter
cloudinary.image('docs/woman-in-shirt.jpg').transformation(Transformation()
	.effect(Effect.generativeReplace().from("shirt")
.to("cable knit sweater")
.preserveGeometry()));
```

```kotlin
cloudinary.image {
	publicId("docs/woman-in-shirt.jpg")
	 effect(Effect.generativeReplace() { from("shirt")
 to("cable knit sweater")
 preserveGeometry() }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/woman-in-shirt.jpg", {effect: "gen_replace:from_shirt;to_cable knit sweater;preserve-geometry_true"})
```

```react_native
import { generativeReplace } from "@cloudinary/url-gen/actions/effect";

new CloudinaryImage("docs/woman-in-shirt.jpg").effect(
  generativeReplace().from("shirt").to("cable knit sweater").preserveGeometry()
);
```

![Comparison of with and without preserve-geometry](https://res.cloudinary.com/demo/image/multi/dl_1000/v1687696503/geo-preserve-comparison.gif "thumb:c_scale,w_350, with_code:false, with_url:false, caption:Replace shirt with sweater - compare with and without preserving geometry, width:350")

Original

Geometrynot preserved

Geometrypreserved

## Limitations
* The generative replace effect can only be used on non-transparent images.
* The use of generative AI means that results may not be 100% accurate.
* The generative replace effect works best on simple objects that are clearly visible.
* Very small objects and very large objects may not be detected.
* Don't attempt to replace faces, hands or text.
* During processing, large images are downscaled to a maximum of 2048 x 2048 pixels, then upscaled back to their original size, which may affect quality.
* There is a [special transformation count](transformation_counts#special_effect_calculations) for the generative replace effect.
* The generative replace effect isn't supported for [animated](animated_images) images or [fetched](fetch_remote_images#fetch_and_deliver_remote_files) images.
* When Cloudinary is generating a derived version, you may get a 423 response returned until the version is ready. You can prepare derived versions in advance using an [eager transformation](eager_and_incoming_transformations#eager_transformations).
* When Cloudinary is generating an [incoming transformation](eager_and_incoming_transformations#incoming_transformations), you may get a 420 response returned, with status `pending` until the asset is ready.
* If you're using our [Asia Pacific data center](admin_api#alternative_data_centers_and_endpoints_premium_feature), you currently can't apply the generative replace effect.
