You can use indexed slice parameters to slice a source image stored in OSS based on the specified size and retrieve the required image. This topic describes the parameters and examples to perform indexed slicing.
Parameter description
Operation name: indexcrop
The following table describes the parameters that are used in the indexcrop operation.
Parameter | Description | Value range |
---|---|---|
x | The length of each image partition during horizontal slicing. Only one of the x and y parameters can be specified. | [1, image width] |
y | The length of each image partition during vertical slicing. Only one of the x and y parameters can be specified. | [1, image height] |
i | The image partition selected after slicing. | [0, maximum number of partitions)
The default value is 0, which indicates the first partition. If you want to return the last partition, perform indexed slicing based on the image size and the value range of the parameter. |
Usage notes
- If the specified index exceeds the number of partitions, the source image is returned.
- If both x and y are specified and their values are valid, the value of y takes effect.
Examples
You can process images by using object URLs, OSS SDKs, or API operations. In this example, object URLs are used. For more information about how to use OSS SDKs and API operations to process images, see IMG implementation modes.
In the following examples, an image in a bucket named oss-console-img-demo-cn-hangzhou in the China (Hangzhou) region is used as the source image. The image can be accessed over the Internet by using the following URL:
- Slice the image along the horizontal axis
Configure the parameters based on the following requirements:
- Slice the image by 100 pixels along the horizontal axis:
indexcrop,x_100
- Retrieve the first partition:
i_0
The URL used to process the image is in the following format: https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/indexcrop,x_100,i_0 - Slice the image by 100 pixels along the horizontal axis:
- Slice the image along the vertical axis
Configure the parameters based on the following requirements:
- Slice the image by 100 pixels along the vertical axis:
indexcrop,y_100
- Retrieve the 11th partition:
i_10
The URL used to process the image is in the following format: https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/indexcrop,y_100,i_10
The source image is returned because the number of partitions after slicing is less than 10. - Slice the image by 100 pixels along the vertical axis: