Image Cropping API Reference

Image Cropping

GET/POST /ai/image/cropping

Image Cropping allows you to resize any image to your desired dimensions. It supports automatic recognition of the main area of the image and crops images with precision, ideal for a wide range of design scenarios.

Request Parameter

Parameter
Type
Required
Description

imageUrl

String

No

Image URL

Either imageUrl or imageBase64 should be input as request parameter. ImageBase64 is preferred when both imageUrl and imageBase64 exist.

Input image size should be between 100×100 pixels(minimum) and 3000×3000 pixels(maximum).

Sample: http://example.jpg/

imageBase64

String

No

Base64 of image

It cannot be empty together with image URL. If both imageUrl and iImageBase64 exist, Base64 is preferred.

Input image size should be between 512×512 pixels(minimum) and 3000×3000 pixels(maximum).

targetWidth

Int

Yes

Target width of image.

Unit:Pixel. Range:100-5000

Sample: 800

targetHeight

Int

Yes

Target height of image.

Unit:Pixel. Range:100-5000

Sample: 800

Sample Request

IopClient client = new IopClient(url, appkey, appSecret);
IopRequest request = new IopRequest();
request.setApiName("/ai/image/cropping");
request.addApiParameter("imageBase64", "\u56FE\u7247base64\u683C\u5F0F");
request.addApiParameter("targetHeight", "200");
request.addApiParameter("imageUrl", "https://ae01.alicdn.com/kf/S99cb7e78ba2b46cc9134b87c323bb617x.png");
request.addApiParameter("targetWidth", "200");
IopResponse response = client.execute(request);
System.out.println(response.getBody());
Thread.sleep(10);

Response Parameters

Parameter
Type
Description

resCode

Number

The returned result code, where 200 indicates success. For detailed error codes, please refer to the error code list.

data

Object

The returned result data.

requestId

String

A unique request ID used for troubleshooting.

success

Boolean

The status of the returned request, indicating whether the request was successful.

resMessage

String

The returned request information.

Sample Response

{
  "data": {
    "imageUrl": "https://ai-business-algo-pai.oss-ap-southeast-1.aliyuncs.com/ai_computing%2Ftmp%2F76cfdba6-414c-4cae-9fd8-2f0bedd014ab.png?OSSAccessKeyId=LTAI5tAGoBnm5eYsnZ5E1zMr&Expires=4935905941&Signature=KXlHdonXT6ktAlqw5x5wLHLy9uk%3D",
    "usage": 1,
    "width": 1000,
    "class": "com.aidc.service.api.client.image.dto.ImageGenResponse",
    "height": 1000
  },
  "requestId": "21410ce717192339411452275ea831",
  "success": true,
  "resCode": 200,
  "resMessage": "success",
  "code": "0",
  "request_id": "212a664f17192339411465542",
  "_trace_id_": "21410ce717192339411452275ea831"
}

Errors

Error Code
Error Message
Description

500

system error

System error.

501

rate limit exceed

The current interface has reached the current limit. Please contact us via navigation bar or email us (aidge_support@service.alibaba.com) to increase the current limit value.

700

invalid input

The format of the input parameters does not meet the requirements, and resMessage will return detailed fields that do not meet the requirements.

801

model failed

Internal call exception, please contact us via navigation bar or email us (aidge_support@service.alibaba.com) for troubleshooting.

1000

content has sensitive data, please try other input

Content has sensitive data and cannot be handled now. Please try other input.

1001

content control failed, please retry

Content has sensitive data, please try other input. If an error persists,please contact us via navigation bar or email us (aidge_support@service.alibaba.com).

1002

content risk filter failed, please contact us

Content risk filter failed, please contact us via navigation bar or email us (aidge_support@service.alibaba.com).

Last updated