You can use custom crop parameters to crop a rectangular image based on a specified 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.

Parameter Description Valid value
w The width of the area that you want to crop. [0, image width].

Default value: the maximum value.

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

Default value: the maximum value.

x The 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]
y The 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]
g The 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 #table_xdo_tzc_rfu.

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.

Tile Calculation method
nw 0, 0
north srcW/2 - w/2, 0
ne srcW - w, 0
west 0, srcH/2 - h/2
center srcW/2 - w/2, srcH/2 - h/2
east srcW - w, srcH/2 - h/2
sw 0, srcH - h
south srcW/2 - w/2, srcH - h
se srcW - 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 error message Advance cut's position is out of image..
  • 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 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: