Resizing Images
This document helps you understand resizing images.
Operation Scenarios
ZOS supports image resizing. You can resize an image based on a specified height, width, or percentage.
Constraints and Restrictions
Supported source formats: JPG, PNG, GIF, WebP, and TIFF. GIF animated images only support resizing by the specified width/height and do not support resizing by percentage.
The size of a source image cannot exceed 20 MB. The width or height cannot exceed 30,000 px, and total pixels cannot exceed 250 million px.
When resizing by percentage: width/height ≤ 16,384 px, and total pixels ≤ 16.78 million. When specifying width & height: Each dimension ≤ 4,096 px.
Note
For animated images (such as GIFs), pixel count is calculated as width*height*number of frames. For static images (such as PNGs), pixel count is calculated as width*height.
Description
Operator: resize
Resizing by Specified Width and Height
Parameter Name | Purpose | Value | Required |
w | Specifies the width of the resized image. | [1,4096] | Yes |
h | Specifies the height of the resized image. | [1,4096] | Yes |
m | Specifies the resizing mode. | lfit (default): Resizes an image proportionally to fit within the specified width and height. | No |
color | Specifies the color for padding when the resizing mode is set to pad. | An RGB hex value, default FFFFFF (white) | No (only when m = pad) |
limit | Specifies whether to scale when the target image is higher than the resolution of the source image. | 1 (default): Returns an image converted based on the resolution of the source image. | No |
Example
Source image size: 400 px*200 px When setting w=300 px and h=160 px, resizing results using different modes are as follows:
l m_fixed
image/resize,w_300,h_160,m_fixed: fixed scales the source image by the specified width and height from to exactly 400 px*200 px to 300 px*160 px, and the proportion is increased.
l pad
image/resize,w_300,h_160,m_pad: pad scales the image proportionally to the maximum size that fits within the rectangle of the specified width and height limits. The current proportion is 300 px*150 px. The remaining h centers the resized image, and fills the remaining part with a white background, resulting in a 300 px *160 px resizing image. However, the areas of h=(0,5) and h=(155,160) are a white background.
l fill
image/resize,w_300,h_160,m_fill: fill proportionally scales the image to the minimum size that extends beyond the rectangle of the specified width and height, i.e., 320 px *160 px. The image is then centered, and the sides are cropped. The partitions of w=(0,10) and w=(310,320) are cropped, producing a 300 px*160 px image.
l mfit
image/resize,w_300,h_160,m_mfit: mfit proportionally scales the source image to the minimum size that extends beyond the rectangle of the specified width and height, i.e., a 320 px *160 px image as the resizing result.
l lfit
image/resize,w_300,h_160,m_lfit: corresponding to mfit, lift proportionally scales the image to the maximum size that fits within the rectangle of the specified width and height, i.e., a resizing image sized 300 px *150 px.
Resizing by Percentage
Parameter Name | Purpose | Value | Required |
p | Resizes by percentage. | [1,1000] | Yes |
FAQ
1. Resizing does not take effect when the specified size is larger than the source image. Why?
Answer: The limit must be set to 0. If set to 1 and only one side of the specified width and height exceeds the source size, that side will use the source image value.
2. Width/height resizing does not produce the expected result. Why?
Answer: Refer to the resizing type. Use the fixed mode to force resizing of the specified width/height.
3. Why does the specified p resizing fail to take effect?
Answer: This may occur if w, h, and p are all specified. When both width/height and percentage parameters are included, width/height takes priority.