Updated on 2024-02-29 GMT+08:00

Common Cropping

You can edit code on OBS Console or make an API call to crop images.

You can start at any point on an image and crop the image into a rectangle with specified width and height. For details, see Table 1.

Parameter: crop

Table 1 Common cropping

Parameter

Value Description

Code Example

g

The location where cropping starts. g can be set to tl, top, tr, left, center, right, bl, bottom, and br. Figure 1 is the 3 x 3 grid illustrating these values. Each value locates at the top left corner of a grid.

image/crop,x_10,y_10,w_200,h_200,g_br

h

Height of the cropped image, ranging [0, original height].

w

Width of the cropped image, ranging [0, original width].

x

x-coordinate of the start point. The top left corner is the default origin. x ranges [0, original width of the image].

y

y-coordinate of the start point. The top left corner is the default origin. y ranges [0, original height of the image].

The origins of cropping are shown as Figure 1.

Figure 1 3 x 3 grid of cropping origins
  • If x is larger than the origin width, or y is larger than the origin height, the cropping cannot be executed and a fault will be returned.
  • If h is larger than the origin height and w is larger than the original width, the image will be cropped to the boundaries.

Example

  • Set the start point of cropping to (1000, 500), and set the width and height of cropping to 1000 both.

    https://obs.region.example.com/image-demo/example.jpg?x-image-process=image/crop,x_1000,y_500,w_1000,h_1000

  • The cropping starts from (10, 10) in the bottom right (br) grid. The width and height are both set to 200.

    https://obs.region.example.com/image-demo/example.jpg?x-image-process=image/crop,x_10,y_10,w_200,h_200,g_br