Resizing Images

This function is available for GUI, Code, and API calling mode. The image can be resized by setting a fixed width, height, or proportion.

  • Long side refers to the side with a larger original to target size ratio, and short side refers to the side with the smaller ratio. For example, if the original image size is 400 px × 200 px and the target size is 100 px × 100 px, the longer side is 400 px and the shorter side is 200 px because 400/100 = 4, 200/100 = 2, and 4 > 2.
  • The longer side of the resized image should not be larger than 4096 x 4, and width x height should not be larger than 4096 x 4096.
  • If you only specify the height or width, the image will be scaled by the side that you specify by default. If you choose fixed width and height mode, the width and height are equal by default. After resized, the image will be returned in original format.
  • By default, when you resize an image, its size will be limited to not be enlarged. If you want the image to become larger after resizing, you need to call the parameter limit,0 to obtain the enlarged image, otherwise the original image will be returned. The format is as follows:

    https://e-share.obs.cn-north-1.myhuaweicloud.com/example.jpg?x-image-process=image/resize,w_500,limit_0

Table 1 describes the parameters in detail.

Operation name: resize

Table 1 Resize settings

Parameter

Value Description

Code Example

m

Type of resizing. The parameter can be set to lfit, mfit, fill, pad, and fixed. The default value is lfit.

  • lfit: Specify a rectangle of w and h, lock the aspect ratio, and obtain the largest image in the rectangle.
  • mfit: Specify a rectangle of w and h, lock the aspect ratio, and obtain the smallest image in the extended area of rectangle.
  • fill: Specify a rectangle of w and h, and lock the aspect ratio. Obtain the smallest image in the extended area of the rectangle, and center and crop it. That is, center and crop the mfit-type image.
  • pad: Specify a rectangle of w and h and lock the aspect ratio. Obtain the largest image in the rectangle and pad the blank area. That is, pad the blank area of the lfit-type image.
  • fixed: Resize the image by setting a fixed width and height.

image/resize,m_lfit,h_100,w_100

p

Percentage of aspect ratio. Other parameters cannot be used simultaneously with p. p ranges [1, 1000]. If the value:

  • < 100: The image is scaled up.
  • = 100: Keep the original size.
  • > 100: The image is scaled down.

image/resize,p_50

h

Height of the resized image, ranging [1, 4096].

image/resize,m_lfit,h_100

w

Width of the image after resizing, ranging [1, 4096].

image/resize,m_fixed,h_100,w_100

l

Specifies the long side of the target thumbnail. Value range: [1, 4096]

The long side has a specified value, and the short side is scaled based on the ratio.

image/resize,l_100

s

Specifies the short side of the target thumbnail. Value range: [1, 4096]

The short side has a specified value, and the long side is scaled based on the ratio.

image/resize,s_100

color

Padding color, used in pad (after resizing) mode.

The color is set by a hexadecimal code, from 000000 to FFFFFF. The default color is white.

image/resize,m_pad,h_100,w_100,color_FF0000

limit

Whether to limit the resized image if it is larger than the original image. The value can be 0 or 1. The default value is 1.

  • 0: Not limit.
  • 1: Limit.

image/resize,p_150,limit_0

Example