---
name: "cropImages"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "3.14.2" }
  - { name: "@ray-js/ray", version: "1.5.30" }
platform:
  - "iOS"
  - "Android"
async: true
title: "cropImages"
---

## cropImages

> [VERSION] BaseKit >= 3.14.2 | @ray-js/ray >= 1.5.30

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Image cropping

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `cropFileList` | `CropImageItemBean[]` | No | - | `3.14.2` | Path of the image to crop |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `fileList` | `string[]` | `3.14.2` | List of output image paths after cropping |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Referenced Types

##### `interface` CropImageItemBean

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `filePath` | `string` | `3.14.2` | Path of the image to crop |
| `topLeftX` | `number` | `3.14.2` | Top-left X coordinate |
| `topLeftY` | `number` | `3.14.2` | Top-left Y coordinate |
| `bottomRightX` | `number` | `3.14.2` | Bottom-right X coordinate |
| `bottomRightY` | `number` | `3.14.2` | Bottom-right Y coordinate |
| `format` | `number` | `3.21.0` | Output type after cropping 0 for jpg, 1 for png, 2 for GIF; default is 0 |
| `rotate` | `number` | `3.24.3` | Rotation angle, range 0–360 degrees |
| `outputImageWidth` | `number` | `3.29.1` | Output width |
| `outputImageHeight` | `number` | `3.29.1` | Output height |


### Examples

#### Demo

```tsx
import { chooseImage, cropImages } from '@ray-js/ray'

// Choose an image from the album, then crop it.
chooseImage({
  count: 1,
  sourceType: ["album"],
  success: res => {
    cropImages({
      cropFileList: res.tempFilePaths.map(filePath => ({
        filePath,
        topLeftX: 0,
        topLeftY: 0,
        bottomRightX: 100,
        bottomRightY: 100,
        format: 0,
        rotate: 0,
        outputImageWidth: 100,
        outputImageHeight: 100,
      })),
      success: data => {
        console.log(data);
      },
      fail: error => {
        console.error(error);
      },
    });
  },
  fail: error => {
    console.error(error);
  },
});
```
