Image Cropping

Introduction

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.

Use Cases

  • Multi-platform content distribution

Merchants can automatically generate content styles in multiple sizes to meet the different image size requirements of various platforms and scenarios.

  • Content placement

Merchants can automatically adjust content dimensions for different platforms and advertising spaces, highlighting the main subject, minimizing whitespace, and emphasizing product key features.

Samples

  • Automatically recognize the main area of the image and crop it precisely.

  • Supporting custom crop size output, allowing adaptation to different platforms and devices.

Input image (input)
Result image(output): 1000*1000
Result image(output): 750*1000

Pricing

To use the API, you are required to choose and purchase an API resource pack from us on a subscription basis.

  • Each resource pack is valid for one calendar year upon successful purchase, and enables you to access the API up to the number of requests specified in the pack. No refunds can be provided.

  • If you need to purchase more QPS due to business requirements, please contact us via navigation bar or email us (aidge_support@service.alibaba.com).

  • Resource packs cannot be used across different products. For example, if you need to use both product text translation and image translation, you must purchase separate resource packs for each.

The prices are as follows:

Capacity
Price (USD)
Unit Price(USD)
QPS Limitations

1,000 images

17

$0.017 /image

2

10,000 images

170

$0.017 /image

2

100,000 images

1700

$0.017 /image

2

Quick Start

1. Sample request

  • Input limitations

  • Image formats: JPEG、JPG、PNG、BMP、WEBP

  • Image size: no more than 4 MB

  • Image resolution: input image is more than 100×100 pixel,less than 5000×5000 pixel.

IopClient client = new IopClient(url, appkey, appSecret);
IopRequest request = new IopRequest();
request.setApiName("/ai/image/cropping");
request.addApiParameter("imageUrl", "https://ae01.alicdn.com/kf/Sa78257f1d9a34dad8ee494178db12ec8l.jpg");
request.addApiParameter("targetWidth", "1000");
request.addApiParameter("imageBase64", "The ImageUrl and Base64 cannot be both empty. If both are provided, the Base64 image will be prioritized. ");
request.addApiParameter("targetHeight", "1000");
IopResponse response = client.execute(request);
System.out.println(response.getBody());
Thread.sleep(10);

2. 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"
}

FAQ

  1. What is the strategy for the Image Cropping product?

Image Cropping can automatically identify the main subject in the picture. It then crops the image to the input target size while preserving as much of the subject as possible.

  1. Will cropping damage the main part of the product?

Cropping might damage the main subject when the picture contains multiple subjects or when the target aspect ratio significantly differs from the original image's aspect ratio.

  1. Can the cropping specify the area or content to be retained?

No. Cropping is based on the identified complete main subject. It is not possible to specify retaining certain local areas or content.

  1. What should I do if an error occurs?

Please refer to the "Errors" section of the API reference for possible causes and recommended solutions.

Last updated