You can use the resize parameters to adjust the size of images stored in Object Storage Service (OSS). This topic describes the parameters used to resize images and provides examples on how to resize images.
Parameters
Operation: resize
The following table describes the parameters that you can configure when you resize images.
- Resize an image based on the specified height and width
Parameter Required Description Valid value m Yes Specifies the type of the resize operation. Default value: lfit. - lfit: OSS resizes the source image proportionally as large as possible within a rectangle based on the specified width and height.
- mfit: OSS resizes the source image proportionally as small as possible beyond a rectangle based on the specified width and height.
- fill: OSS resizes the source image proportionally as small as possible beyond a rectangle, and then crops the resized image from the center based on the specified width and height.
- pad: OSS resizes the source image as large as possible within a rectangle based on the specified width and height, and fills the empty space by using the specified color.
- fixed: OSS forcibly resizes the source image based on the specified width and height.
Note When you set the parameter to lfit or mfit to proportionally resize an image, the ratio of w/h of the source image is rounded to numbers if the ratio is a decimal.w Yes Specifies the width to which you want to resize the image. [1,4096] h Yes Specifies the height to which you want to resize the image. [1,4096] l Yes Specifies the length of the longer side to which you want to resize the image. Note Longer side refers to the side with the larger ratio of the source length to the requested length. Shorter side refers to the side with the smaller ratio of the source length to the requested length. For example, if a source image is resized from 400 × 200 pixels to 800 × 100 pixels, the source-to-requested ratios are 0.5 (400/800) and 2 (200/100). 0.5 is smaller than 2. Therefore, the 200-pixel side is the longer side, and the 400-pixel side is the shorter side.[1,4096] s Yes Specifies the length of the shorter side to which you want to resize the image. [1,4096] limit No Specifies whether to perform the resize operation when the resized image is larger than the source image. Valid values: 0 and 1. Default value: 1. - 1: OSS returns the source image without resizing the image.
- 0: OSS resizes the source image based on the specified parameter.
color Yes (only when the value of m
is pad)When you set the resize type to pad, you can select a color to fill the empty space. RGB color values. For example, 000000 indicates black, and FFFFFF indicates white. Default value: FFFFFF (white).
Example: The size of the source image is 200 × 100 pixels. The w parameter is set to 150 pixels, and the h parameter is set to 80 pixels. The source image is resized to different sizes when you specify different resize types.- lfit
- Proportional resizing: The value of w/h of the source image must be equal to that of the resized image. Therefore, if w is 150 pixels, h is 75 pixels. If h is 80 pixels, w is 160 pixels.
- Maximum image within a rectangle based on the specified width and height: The value of w*h of the resized image cannot exceed 150 × 80 pixels.
The size of the resized image is 150 × 75 pixels based on the preceding conditions.
- mfit
- Proportional resizing: The value of w/h of the source image must be equal to that of the resized image. Therefore, if w is 150 pixels, h is 75 pixels. If h is 80 pixels, w is 160 pixels.
- Minimum image beyond a rectangle based on the specified width and height: The resized image must be a minimum rectangle whose size is greater than 150 × 80 pixels.
The size of the resized image is 160 × 80 pixels based on the preceding conditions.
- fill
The fill parameter is used to resize the source image proportionally as small as possible beyond a rectangle and crop the resized image based on the specified width and height. The source image is resized to 160 × 80 pixels, and w is cropped to 150 pixels from the center to obtain a resized image of 150 × 80 pixels.
- pad
The pad parameter is used to resize the source image as large as possible within a rectangle and fill the empty space based on the specified width and height. The source image is resized to 150 × 75 pixels, and h is centered and filled to 80 pixels to obtain a resized image of 150 × 80 pixels.
- fixed
The fixed parameter is used to resize the image based on the specified width and height. If the width and height ratio of the image is different from that of the source image, the image is deformed.
- Resize an image proportionally
Parameter Required Description Value value p Yes OSS resizes an image by percentage. [1,1000] A percentage smaller than 100 indicates that the image is scaled down. A percentage greater than 100 indicates that the image is scaled up.
Usage notes
- Limits on source images
- Only JPG, PNG, BMP, GIF, WebP, and TIFF images are supported. GIF images can be resized based on the specified width and height but cannot be resized proportionally. GIF images become static images when you resize the images proportionally.
- The size of the source image cannot exceed 20 MB.
- The width or height of the source image cannot exceed 30,000 pixels. The total number
of pixels of the source image cannot exceed 250 million.
The total number of pixels of a dynamic image, such as a GIF image, is calculated by using the following formula:
Width × Height × Number of image frames
. The total number of pixels of a static image, such as a PNG image, is calculated by using the following formula:Width × Height
.
- Limits on resized images
The width or height of a resized image cannot exceed 16,384 pixels. The total number of pixels of the resized image cannot exceed 16,777,216.
- Priority of resize operations
If you use a URL to resize an image based on the specified height and width and the specified proportion at the same time, the image is resized based on the specified height and width.
- Resize operations with only the image width or height specified
- The source image is resized proportionally when proportional resizing is performed. For example, if you resize the height of a source image from 200 × 100 pixels to 100 pixels, the width of the source image is resized to 50 pixels.
- The source image is resized based on the specified width and height. For example, if you resize the height of a source image from 200 × 100 pixels to 100 pixels, the width of the source image is resized to 100 pixels.
- If you set the m parameter to mfit and specify a value for l or s, the longer side or the shorter side of the image is scaled based on the specified value of l or s.
- If you specify the m parameter and specify a value for w or h, the values specified for l and s do not take effect.
- By default, if the size of the resized image is larger than that of the source image,
the source image is returned. You can add the
limit_0
parameter to enlarge the image. The URL used to enlarge the image is in the following format:https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,w_500,limit_0
.
Examples
In the following examples, an image in a bucket named image-demo in the China (Hangzhou) region is used as the source image. The image can be accessed over the Internet by using the following URL:
- Resize the image proportionally
- Based on the width or height
Configure parameters to resize the image:
- Resize the source image to a height of 100 pixels:
resize,h_100
- Set the resize type to lfit:
m_lfit
The URL used to process the image is in the following format: http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,h_100,m_lfit - Resize the source image to a height of 100 pixels:
- Based on the longer side
Resize the source image based on the longer side of 100 pixels:
resize,l_100
The URL used to process the image is in the following format: http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,l_100
- Based on the width or height
- Resize the image based on the specified width and height
Configure parameters to resize the image:
- Resize the source image to a width and a height of 100 pixels:
resize,h_100,w_100
- Set the resize type to fixed:
m_fixed
The URL used to process the image is in the following format: http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,m_fixed,h_100,w_100 - Resize the source image to a width and a height of 100 pixels:
- Crop the image based on the specified width and height
Configure parameters to resize the image:
- Resize the source image to a width and a height of 100 pixels:
resize,h_100,w_100
- Set the resize type to fill:
m_fill
The URL used to process the image is in the following format: http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,m_fill,h_100,w_100 - Resize the source image to a width and a height of 100 pixels:
- Resize the source image based on the specified width and height and fill the empty
space
Configure parameters to resize the image:
- Resize the source image to a width and a height of 100 pixels:
resize,h_100,w_100
- Set the resize type to pad:
m_pad
- Fill the empty space in red:
color_FF0000
The URL used to process the image is in the following format: http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,m_pad,h_100,w_100,color_FF0000 - Resize the source image to a width and a height of 100 pixels:
- Resize an image proportionally
Configure parameters to resize the image:
Resize the source image by 50%:
resize,p_50
The URL used to process the image is in the following format: http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,p_50
FAQ
How do I access a resized image if the access control list (ACL) of the image is private?
To access the image, you must add signature information to the URL of the image. For more information about how to obtain the URL of an object, see How do I obtain the URL of an uploaded object?.