You can use custom crop parameters to crop a rectangular image based on a specific size from a source image stored in Object Storage Service (OSS). This topic describes how to crop images and provides examples.

Parameters

Operation: crop.

The following table describes the parameters.

ParameterDescriptionValue range
wThe width of the area that you want to crop. [0, image width]

Default value: the maximum value.

hThe height of the area that you want to crop. [0, image height]

Default value: the maximum value.

xThe X coordinate of the area that you want to crop. The default value is the X coordinate of the upper-left corner of the image. [0, image bound]
yThe Y coordinate of the area that you want to crop. The default value is the Y coordinate of the upper-left corner of the image. [0, image bound]
gThe position of the area that you want to crop in a 3 x 3 grid. The image is located in a 3 x 3 grid. The grid has nine tiles.
  • nw: upper left
  • north: upper middle
  • ne: upper right
  • west: middle left
  • center: center
  • east: middle right
  • sw: lower left
  • south: lower middle
  • se: lower right

For more information about how to calculate the position of each tile, see the following table.

The following table describes how to calculate the position of each tile in a 3 x 3 grid. srcW specifies the width of the source image and srcH specifies the height of the source image.

TileCalculation method
nw0, 0
northsrcW/2 - w/2, 0
nesrcW - w, 0
west0, srcH/2 - h/2
centersrcW/2 - w/2, srcH/2 - h/2
eastsrcW - w, srcH/2 - h/2
sw0, srcH - h
sourthsrcW/2 - w/2, srcH - h
sesrcW - w, srcH - h

Usage notes

  • If the specified starting abscissa or ordinate values exceed those of the source image, the system returns BadRequest and the Advance cut's position is out of image. error message.
  • If the width and height specified from the starting point exceed those of the source image, the source image is cropped to the boundaries.

Examples

You can use object URLs and OSS SDKs, or call API operations to configure Image Processing (IMG) parameters that are used to process images. In this topic, object URLs are used. You can use object URLs to configure IMG parameters only for public-read images. If you want to configure IMG parameters for private images, use OSS SDKs or call API operations. For more information, see IMG implementation modes.

In the following examples, an image in a bucket named oss-console-img-demo-cn-hangzhou-3az in the China (Hangzhou) region is used as the source image. The image can be accessed over the Internet by using the following URL: