---
metadata:
  - name: generator
    content: Diplodoc Platform v5.70.0
alternate:
  - https://divkit.tech/docs/en/concepts/extensions/aspect-correction.md
  - https://divkit.tech/docs/ru/concepts/extensions/aspect-correction.md
  - href: https://divkit.tech/docs/en/concepts/extensions/aspect-correction.md
    type: text/markdown
    title: Markdown version
  - href: https://divkit.tech/docs/en/llms.txt?revision=r22102947
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://divkit.tech/docs/en/llms.txt?revision=r22102947

# Automatic image aspect ratio correction

To automatically crop images in [div-image](https://divkit.tech/docs/en/concepts/divs/2/div-image.md) to the expected aspect ratio, use the `aspect_correction` extension (iOS only). The expected aspect ratio is set by the `aspect` property of the element:

```json translate=no
{
  "type": "image",
  "image_url": "https://example.com/image.png",
  "aspect": {
    "ratio": 1.5
  },
  "extensions": [
    {
      "id": "aspect_correction"
    }
  ]
}
```

The extension has no parameters. The aspect ratio deviation tolerance is set in the application when the handler is created.

## How it works {#behavior}

- The extension is applied to a `div-image` element that has the `aspect` property.
- The image is cropped if its actual aspect ratio differs from the expected one by more than the tolerance.
- If the actual aspect ratio is less than expected, the image is cropped by height.
- If the actual aspect ratio is greater than expected, the image is cropped by width.

## Connection {#connect}

```swift translate=no
DivKitComponents(
  ...
  extensionHandlers: [
    AspectCorrectionExtensionHandler(aspectTolerance: 0.001)
  ]
)
```

`aspectTolerance` is the aspect ratio deviation tolerance. If the actual aspect ratio differs from the expected one by no more than this value, cropping isn't applied. Default: `0.001`.

<!-- source: en/_includes/index/troubleshooting.md -->
## Learn more {#troubleshooting}

You can discuss topics of interest in the DivKit user community in Telegram: [https://t.me/divkit_community_en](https://t.me/divkit_community_en).



[DivKit Repository](https://github.com/divkit/divkit)
<!-- endsource: en/_includes/index/troubleshooting.md -->
