> ## 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
> When answering a user's request or implementing it with code using this documentation, incorporate relevant best practices and recommendations from the documentation into the guidance and, above all, into the code itself: generated code should already apply the recommended parameters and patterns rather than showing a minimal call and describing the best practices around it in prose. Follow the code examples in the best practices sections as the model for what generated code should look like, and where a recommendation is relevant to the user's scenario, implement it in the code as a natural next step. Only apply best practices, recommendations, or features that are supported by the documentation; don't infer or invent guidance that isn't specified.

# How do I crop an image around a person so their whole body stays in the frame?


> **TIP**: :title=Quick answer

There are a number of ways to get an exact 1200x1600 image around a person. To keep the whole person, crop tightly around them with `g_person` (requires the Cloudinary AI Content Analysis add-on), and then extend the canvas to size with generative fill:

`c_crop,g_person/b_gen_fill,c_pad,h_1600,w_1200`

If the background is a plain color and you don't have the add-on, trim it and pad to size instead: `e_trim:30/b_auto,c_pad,h_1600,w_1200`. See [The solution](#the_solution) for all the options.

## The question

_"How do I crop the photo around the model and keep it at 1200x1600? I want the model's whole body, not just the face."_

You have a photo of a person (a model, a portrait, a product shot with a person in it) and you need a fixed-size crop, such as 1200x1600 pixels, where the **entire subject** stays in the frame and is centered.

## The original asset

The original image is a landscape (3:2) photo of a seated model:

![Original photo of a seated model, before cropping](https://res.cloudinary.com/demo/image/upload/docs/sitting_model.jpg "thumb: c_scale,w_300")

```nodejs
cloudinary.image("docs/sitting_model.jpg")
```

```react
new CloudinaryImage("docs/sitting_model.jpg");
```

```vue
new CloudinaryImage("docs/sitting_model.jpg");
```

```angular
new CloudinaryImage("docs/sitting_model.jpg");
```

```js
new CloudinaryImage("docs/sitting_model.jpg");
```

```python
CloudinaryImage("docs/sitting_model.jpg").image()
```

```php
(new ImageTag('docs/sitting_model.jpg'));
```

```java
cloudinary.url().transformation(new Transformation().imageTag("docs/sitting_model.jpg");
```

```ruby
cl_image_tag("docs/sitting_model.jpg")
```

```csharp
cloudinary.Api.UrlImgUp.BuildImageTag("docs/sitting_model.jpg")
```

```dart
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation());
```

```swift
imageView.cldSetImage(cloudinary.createUrl().generate("docs/sitting_model.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().generate("docs/sitting_model.jpg");
```

```flutter
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation());
```

```kotlin
cloudinary.image {
	publicId("docs/sitting_model.jpg") 
}.generate()
```

```jquery
$.cloudinary.image("docs/sitting_model.jpg")
```

```react_native
new CloudinaryImage("docs/sitting_model.jpg");
```

## The solution

The best approach depends on whether you can use the Cloudinary AI Content Analysis add-on, and on whether any part of the person can be cut off:

* [Option 1](#option_1_crop_with_code_c_fill_code_and_code_g_person_code): crop to the exact size around the detected person (requires the add-on).
* [Option 2](#option_2_crop_tightly_around_the_person_then_extend_the_canvas): crop tightly around the whole person, then extend the canvas to the exact size. This keeps the whole person in the frame (requires the add-on).
* [Option 3](#option_3_crop_with_code_c_fill_code_and_code_g_auto_code): crop with automatic gravity (no add-on required).
* [Option 4](#option_4_trim_the_background_then_pad_to_size): if the background is a plain color, trim it and pad the image to size (no add-on required).

### Option 1: Crop with `c_fill` and `g_person`

Use the `c_fill` crop mode with the `g_person` gravity, which is part of the [Cloudinary AI Content Analysis](cloudinary_ai_content_analysis_addon) add-on. It uses object detection to find the person in the image and bases the crop on them, instead of on the face or on the most prominent area:

![Photo of a seated model cropped to 1200x1600 with g_person](https://res.cloudinary.com/demo/image/upload/c_fill,g_person,h_1600,w_1200/docs/sitting_model.jpg "thumb: c_scale,w_300")

```nodejs
cloudinary.image("docs/sitting_model.jpg", {gravity: "person", height: 1600, width: 1200, crop: "fill"})
```

```react
import { fill } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(focusOn(person()))
);
```

```vue
import { fill } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(focusOn(person()))
);
```

```angular
import { fill } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(focusOn(person()))
);
```

```js
import { fill } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(focusOn(person()))
);
```

```python
CloudinaryImage("docs/sitting_model.jpg").image(gravity="person", height=1600, width=1200, crop="fill")
```

```php
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\Gravity;
use Cloudinary\Transformation\FocusOn;

(new ImageTag('docs/sitting_model.jpg'))
	->resize(Resize::fill()->width(1200)
->height(1600)
	->gravity(
	Gravity::focusOn(
	FocusOn::person()))
	);
```

```java
cloudinary.url().transformation(new Transformation().gravity("person").height(1600).width(1200).crop("fill")).imageTag("docs/sitting_model.jpg");
```

```ruby
cl_image_tag("docs/sitting_model.jpg", gravity: "person", height: 1600, width: 1200, crop: "fill")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Gravity("person").Height(1600).Width(1200).Crop("fill")).BuildImageTag("docs/sitting_model.jpg")
```

```dart
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation()
	.resize(Resize.fill().width(1200)
.height(1600)
	.gravity(
	Gravity.focusOn(
	FocusOn.person()))
	));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setGravity("person").setHeight(1600).setWidth(1200).setCrop("fill")).generate("docs/sitting_model.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().gravity("person").height(1600).width(1200).crop("fill")).generate("docs/sitting_model.jpg");
```

```flutter
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation()
	.resize(Resize.fill().width(1200)
.height(1600)
	.gravity(
	Gravity.focusOn(
	FocusOn.person()))
	));
```

```kotlin
cloudinary.image {
	publicId("docs/sitting_model.jpg")
	 resize(Resize.fill() { width(1200)
 height(1600)
	 gravity(
	Gravity.focusOn(
	FocusOn.person()))
	 }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/sitting_model.jpg", {gravity: "person", height: 1600, width: 1200, crop: "fill"})
```

```react_native
import { fill } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(focusOn(person()))
);
```

The result is exactly 1200x1600 pixels. Keep these points in mind when using `g_person`:

* If no person is detected, the gravity falls back to the center of the image.
* If there are several people, `g_person` bases the crop on the most prominent one.
* To prefer people but still let automatic gravity consider the rest of the image, use `g_auto:person`.
* By default, delivery URLs that use the add-on must be signed or eagerly generated. For details, see [Signed URLs](cloudinary_ai_content_analysis_object_aware_cropping#signed_urls).

> **NOTE**:
>
> To use `g_person` in your own product environment, you first need to subscribe to the Cloudinary AI Content Analysis add-on:
> 1. Make sure you're logged in to your Cloudinary account, and then go to the [Add-ons](https://console.cloudinary.com/app/settings/addons) page in the Console Settings.
> 2. Select the **Cloudinary AI Content Analysis** add-on and choose a plan.
> For more information, see [Registering for add-ons](cloudinary_add_ons#registering_for_add_ons).

For more details, see [Object-aware cropping](cloudinary_ai_content_analysis_object_aware_cropping).

### Option 2: Crop tightly around the person, then extend the canvas

`c_fill` always has to cut away part of the image to reach a different aspect ratio, so even with `g_person` it can cut off part of the person, as the [comparison below](#how_the_result_depends_on_the_aspect_ratio) shows. If you can't afford to lose any of the person, and you don't mind some added background, do it in two steps:

1. `c_crop,g_person` crops tightly around the whole detected person, without a fixed size.
2. `b_gen_fill,c_pad,h_1600,w_1200` pads the result out to exactly 1200x1600, and uses [generative fill](generative_fill) to extend the background with realistic generated pixels instead of a flat color.

![Photo of a seated model cropped around the person and extended to 1200x1600 with generative fill](https://res.cloudinary.com/demo/image/upload/c_crop,g_person/b_gen_fill,c_pad,h_1600,w_1200/docs/sitting_model.jpg "with_image:false")

```nodejs
cloudinary.image("docs/sitting_model.jpg", {transformation: [
  {gravity: "person", crop: "crop"},
  {background: "gen_fill", height: 1600, width: 1200, crop: "pad"}
  ]})
```

```react
import { crop, pad } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { generativeFill } from "@cloudinary/url-gen/qualifiers/background";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg")
  .resize(crop().gravity(focusOn(person())))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(generativeFill())
  );
```

```vue
import { crop, pad } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { generativeFill } from "@cloudinary/url-gen/qualifiers/background";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg")
  .resize(crop().gravity(focusOn(person())))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(generativeFill())
  );
```

```angular
import { crop, pad } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { generativeFill } from "@cloudinary/url-gen/qualifiers/background";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg")
  .resize(crop().gravity(focusOn(person())))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(generativeFill())
  );
```

```js
import { crop, pad } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { generativeFill } from "@cloudinary/url-gen/qualifiers/background";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg")
  .resize(crop().gravity(focusOn(person())))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(generativeFill())
  );
```

```python
CloudinaryImage("docs/sitting_model.jpg").image(transformation=[
  {'gravity': "person", 'crop': "crop"},
  {'background': "gen_fill", 'height': 1600, 'width': 1200, 'crop': "pad"}
  ])
```

```php
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\Gravity;
use Cloudinary\Transformation\Background;
use Cloudinary\Transformation\FocusOn;

(new ImageTag('docs/sitting_model.jpg'))
	->resize(Resize::crop()
	->gravity(
	Gravity::focusOn(
	FocusOn::person()))
	)
	->resize(Resize::pad()->width(1200)
->height(1600)
	->background(
	Background::generativeFill())
	);
```

```java
cloudinary.url().transformation(new Transformation()
  .gravity("person").crop("crop").chain()
  .background("gen_fill").height(1600).width(1200).crop("pad")).imageTag("docs/sitting_model.jpg");
```

```ruby
cl_image_tag("docs/sitting_model.jpg", transformation: [
  {gravity: "person", crop: "crop"},
  {background: "gen_fill", height: 1600, width: 1200, crop: "pad"}
  ])
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Gravity("person").Crop("crop").Chain()
  .Background("gen_fill").Height(1600).Width(1200).Crop("pad")).BuildImageTag("docs/sitting_model.jpg")
```

```dart
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation()
	.resize(Resize.crop()
	.gravity(
	Gravity.focusOn(
	FocusOn.person()))
	)
	.resize(Resize.pad().width(1200)
.height(1600)
	.background(
	Background.generativeFill())
	));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
  .setGravity("person").setCrop("crop").chain()
  .setBackground("gen_fill").setHeight(1600).setWidth(1200).setCrop("pad")).generate("docs/sitting_model.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation()
  .gravity("person").crop("crop").chain()
  .background("gen_fill").height(1600).width(1200).crop("pad")).generate("docs/sitting_model.jpg");
```

```flutter
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation()
	.resize(Resize.crop()
	.gravity(
	Gravity.focusOn(
	FocusOn.person()))
	)
	.resize(Resize.pad().width(1200)
.height(1600)
	.background(
	Background.generativeFill())
	));
```

```kotlin
cloudinary.image {
	publicId("docs/sitting_model.jpg")
	 resize(Resize.crop() {
	 gravity(
	Gravity.focusOn(
	FocusOn.person()))
	 })
	 resize(Resize.pad() { width(1200)
 height(1600)
	 background(
	Background.generativeFill())
	 }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/sitting_model.jpg", {transformation: [
  {gravity: "person", crop: "crop"},
  {background: "gen_fill", height: 1600, width: 1200, crop: "pad"}
  ]})
```

```react_native
import { crop, pad } from "@cloudinary/url-gen/actions/resize";
import { focusOn } from "@cloudinary/url-gen/qualifiers/gravity";
import { generativeFill } from "@cloudinary/url-gen/qualifiers/background";
import { person } from "@cloudinary/url-gen/qualifiers/focusOn";

new CloudinaryImage("docs/sitting_model.jpg")
  .resize(crop().gravity(focusOn(person())))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(generativeFill())
  );
```

The output is exactly 1200x1600. Generative fill invents new content, so check that the result looks right for your images. To fill the extra space with a plain color instead, replace `b_gen_fill` with a color, such as `b_white`. Option 2 requires the [Cloudinary AI Content Analysis](cloudinary_ai_content_analysis_addon) add-on for `g_person`, and the same [signed URL](cloudinary_ai_content_analysis_object_aware_cropping#signed_urls) requirement applies.

### Option 3: Crop with `c_fill` and `g_auto`

If you don't use the add-on, use the `c_fill` crop mode with automatic gravity (`g_auto`). Cloudinary analyzes the image and keeps the most important area in the frame, giving priority to faces by default. For this photo, the result keeps the whole model in the frame:

![Photo of a seated model cropped to 1200x1600 with g_auto](https://res.cloudinary.com/demo/image/upload/c_fill,g_auto,h_1600,w_1200/docs/sitting_model.jpg "thumb: c_scale,w_300")

```nodejs
cloudinary.image("docs/sitting_model.jpg", {gravity: "auto", height: 1600, width: 1200, crop: "fill"})
```

```react
import { fill } from "@cloudinary/url-gen/actions/resize";
import { autoGravity } from "@cloudinary/url-gen/qualifiers/gravity";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(autoGravity())
);
```

```vue
import { fill } from "@cloudinary/url-gen/actions/resize";
import { autoGravity } from "@cloudinary/url-gen/qualifiers/gravity";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(autoGravity())
);
```

```angular
import { fill } from "@cloudinary/url-gen/actions/resize";
import { autoGravity } from "@cloudinary/url-gen/qualifiers/gravity";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(autoGravity())
);
```

```js
import { fill } from "@cloudinary/url-gen/actions/resize";
import { autoGravity } from "@cloudinary/url-gen/qualifiers/gravity";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(autoGravity())
);
```

```python
CloudinaryImage("docs/sitting_model.jpg").image(gravity="auto", height=1600, width=1200, crop="fill")
```

```php
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\Gravity;

(new ImageTag('docs/sitting_model.jpg'))
	->resize(Resize::fill()->width(1200)
->height(1600)
	->gravity(
	Gravity::autoGravity())
	);
```

```java
cloudinary.url().transformation(new Transformation().gravity("auto").height(1600).width(1200).crop("fill")).imageTag("docs/sitting_model.jpg");
```

```ruby
cl_image_tag("docs/sitting_model.jpg", gravity: "auto", height: 1600, width: 1200, crop: "fill")
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation().Gravity("auto").Height(1600).Width(1200).Crop("fill")).BuildImageTag("docs/sitting_model.jpg")
```

```dart
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation()
	.resize(Resize.fill().width(1200)
.height(1600)
	.gravity(
	Gravity.autoGravity())
	));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setGravity("auto").setHeight(1600).setWidth(1200).setCrop("fill")).generate("docs/sitting_model.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation().gravity("auto").height(1600).width(1200).crop("fill")).generate("docs/sitting_model.jpg");
```

```flutter
cloudinary.image('docs/sitting_model.jpg').transformation(Transformation()
	.resize(Resize.fill().width(1200)
.height(1600)
	.gravity(
	Gravity.autoGravity())
	));
```

```kotlin
cloudinary.image {
	publicId("docs/sitting_model.jpg")
	 resize(Resize.fill() { width(1200)
 height(1600)
	 gravity(
	Gravity.autoGravity())
	 }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/sitting_model.jpg", {gravity: "auto", height: 1600, width: 1200, crop: "fill"})
```

```react_native
import { fill } from "@cloudinary/url-gen/actions/resize";
import { autoGravity } from "@cloudinary/url-gen/qualifiers/gravity";

new CloudinaryImage("docs/sitting_model.jpg").resize(
  fill()
    .width(1200)
    .height(1600)
    .gravity(autoGravity())
);
```

The result is exactly 1200x1600 pixels, with the model's head, body, and feet all in the frame.

> **NOTE**: `c_fill` always produces the exact `w_` x `h_` size you ask for. If the source image has a different aspect ratio, `c_fill` resizes the image to cover the area and then crops away the overflow. The gravity decides which part is cropped away.

### Option 4: Trim the background, then pad to size

If the photo has a plain, single-color background (such as a studio shot), you don't need to crop the person at all. Trim away the plain background, and then pad the result out to the exact size with a matching color:

1. `e_trim:30` removes the border areas that match the background color. The number is the color tolerance (the higher the value, the more it removes), so increase it if some background remains, and lower it if it starts to cut into the person.
2. `b_auto,c_pad,h_1600,w_1200` fits the whole trimmed image inside 1200x1600, and fills the rest with a color that matches the image (`b_auto`). To use a specific color, replace `b_auto` with a color, such as `b_white`.

![Studio photo of a seated model trimmed and padded to 1200x1600](https://res.cloudinary.com/demo/image/upload/e_trim:30/b_auto,c_pad,h_1600,w_1200/docs/female-model-01.jpg "thumb: c_scale,w_300")

```nodejs
cloudinary.image("docs/female-model-01.jpg", {transformation: [
  {effect: "trim:30"},
  {background: "auto", height: 1600, width: 1200, crop: "pad"}
  ]})
```

```react
import { trim } from "@cloudinary/url-gen/actions/reshape";
import { pad } from "@cloudinary/url-gen/actions/resize";
import { auto } from "@cloudinary/url-gen/qualifiers/background";

new CloudinaryImage("docs/female-model-01.jpg")
  .reshape(trim().colorSimilarity(30))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(auto())
  );
```

```vue
import { trim } from "@cloudinary/url-gen/actions/reshape";
import { pad } from "@cloudinary/url-gen/actions/resize";
import { auto } from "@cloudinary/url-gen/qualifiers/background";

new CloudinaryImage("docs/female-model-01.jpg")
  .reshape(trim().colorSimilarity(30))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(auto())
  );
```

```angular
import { trim } from "@cloudinary/url-gen/actions/reshape";
import { pad } from "@cloudinary/url-gen/actions/resize";
import { auto } from "@cloudinary/url-gen/qualifiers/background";

new CloudinaryImage("docs/female-model-01.jpg")
  .reshape(trim().colorSimilarity(30))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(auto())
  );
```

```js
import { trim } from "@cloudinary/url-gen/actions/reshape";
import { pad } from "@cloudinary/url-gen/actions/resize";
import { auto } from "@cloudinary/url-gen/qualifiers/background";

new CloudinaryImage("docs/female-model-01.jpg")
  .reshape(trim().colorSimilarity(30))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(auto())
  );
```

```python
CloudinaryImage("docs/female-model-01.jpg").image(transformation=[
  {'effect': "trim:30"},
  {'background': "auto", 'height': 1600, 'width': 1200, 'crop': "pad"}
  ])
```

```php
use Cloudinary\Transformation\Reshape;
use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\Background;

(new ImageTag('docs/female-model-01.jpg'))
	->reshape(Reshape::trim()->colorSimilarity(30))
	->resize(Resize::pad()->width(1200)
->height(1600)
	->background(
	Background::auto())
	);
```

```java
cloudinary.url().transformation(new Transformation()
  .effect("trim:30").chain()
  .background("auto").height(1600).width(1200).crop("pad")).imageTag("docs/female-model-01.jpg");
```

```ruby
cl_image_tag("docs/female-model-01.jpg", transformation: [
  {effect: "trim:30"},
  {background: "auto", height: 1600, width: 1200, crop: "pad"}
  ])
```

```csharp
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Effect("trim:30").Chain()
  .Background("auto").Height(1600).Width(1200).Crop("pad")).BuildImageTag("docs/female-model-01.jpg")
```

```dart
cloudinary.image('docs/female-model-01.jpg').transformation(Transformation()
	.reshape(Reshape.trim().colorSimilarity(30))
	.resize(Resize.pad().width(1200)
.height(1600)
	.background(
	Background.auto())
	));
```

```swift
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
  .setEffect("trim:30").chain()
  .setBackground("auto").setHeight(1600).setWidth(1200).setCrop("pad")).generate("docs/female-model-01.jpg")!, cloudinary: cloudinary)
```

```android
MediaManager.get().url().transformation(new Transformation()
  .effect("trim:30").chain()
  .background("auto").height(1600).width(1200).crop("pad")).generate("docs/female-model-01.jpg");
```

```flutter
cloudinary.image('docs/female-model-01.jpg').transformation(Transformation()
	.reshape(Reshape.trim().colorSimilarity(30))
	.resize(Resize.pad().width(1200)
.height(1600)
	.background(
	Background.auto())
	));
```

```kotlin
cloudinary.image {
	publicId("docs/female-model-01.jpg")
	 reshape(Reshape.trim() { colorSimilarity(30) })
	 resize(Resize.pad() { width(1200)
 height(1600)
	 background(
	Background.auto())
	 }) 
}.generate()
```

```jquery
$.cloudinary.image("docs/female-model-01.jpg", {transformation: [
  {effect: "trim:30"},
  {background: "auto", height: 1600, width: 1200, crop: "pad"}
  ]})
```

```react_native
import { trim } from "@cloudinary/url-gen/actions/reshape";
import { pad } from "@cloudinary/url-gen/actions/resize";
import { auto } from "@cloudinary/url-gen/qualifiers/background";

new CloudinaryImage("docs/female-model-01.jpg")
  .reshape(trim().colorSimilarity(30))
  .resize(
    pad()
      .width(1200)
      .height(1600)
      .background(auto())
  );
```

The result is exactly 1200x1600, and the whole person is in the frame, because nothing is cropped away except the background.

> **NOTE**: Use `c_pad` (or `c_lpad`) for the second step, not `c_mpad`. The `c_mpad` mode never scales an image down, so if the trimmed image is larger than the requested size, it's left at its trimmed size instead of being resized to 1200x1600. Use `c_mpad` only if the trimmed image is smaller than the requested size.

This works only when the background is plain. If it has a pattern, a gradient, or other objects, `e_trim` can leave some of it behind, or cut into the person at a higher tolerance. In that case, use Option 2.

## How the result depends on the aspect ratio

The same transformation can crop different images very differently, because the gravity can only choose which area to keep, and the amount that has to be cut away depends on the aspect ratio of the original image compared with the one you request. All of these images are cropped to 1200x1600 (3:4):

Seated model (3:2 landscape)

Original
<code>c_fill,g_auto
<code>c_fill,g_person

Seated woman (1.85:1 wide landscape)

Original
<code>c_fill,g_auto
<code>c_fill,g_person

Seated woman (2:3 portrait)

Original
<code>c_fill,g_auto
<code>c_fill,g_person

Standing woman, subject fills the frame (2:3 portrait)

Original
<code>c_fill,g_auto
<code>c_fill,g_person

In these examples:

* **Seated model (3:2):** both gravities keep the whole model.
* **Wide landscape (1.85:1):** `g_auto` keeps the face and upper body, but cuts off part of the legs. `g_person` cuts off part of the head, because so much of the width has to be removed.
* **Portrait, seated (2:3):** both keep the whole person. The `g_person` crop is tighter and off-center.
* **Portrait, subject fills the frame (2:3):** there's little room to crop, and whichever gravity you choose cuts off something. `g_auto` cuts off the feet, and `g_person` cuts off the top of the head.

When the subject fills most of the original image, or when the original is much wider than the requested size, no gravity can promise to keep all of the person. Use [Option 2](#option_2_crop_tightly_around_the_person_then_extend_the_canvas), which crops around the whole person and then adds background, or [Option 4](#option_4_trim_the_background_then_pad_to_size) if the background is a plain color, instead of cutting away more of the image.

## Related topics

* [Resizing and cropping images](resizing_and_cropping)
* [Object-aware cropping](cloudinary_ai_content_analysis_object_aware_cropping)
* [Generative fill](generative_fill)
* [Face-detection based transformations](face_detection_based_transformations)
* [Why is my image blurry?](ts_why_is_my_image_blurry): if the cropped image looks soft after you enlarge it.
