Use the resize action to scale images to a specific width, height, or percentage. This is useful when your platform or app requires specific image sizes — for example, profile pictures, thumbnails, or assets for different screen densities.
The image editing feature of Alibaba Cloud CDN, the image editing feature of DCDN, and the Image Processing (IMG) feature of Object Storage Service (OSS) are three separate features and cannot be used interchangeably.
Image editing is free of charge until further notice.
Converting between image formats (for example, JPEG to WebP, or PNG to WebP) may produce a larger file because different formats use different compression algorithms. To reduce the output file size, set the quality parameter to lower the image quality.Limits
The
resizeaction only scales images down. If the target dimensions are larger than the original, the image is returned unchanged.Setting any parameter to a negative value returns the image unchanged.
The total pixel count of the output image cannot exceed 16,777,216 pixels.
Parameters
Action: resize
| Parameter | Full name | Description | Valid values |
|---|---|---|---|
w | Width | Target width in pixels. | Integer. Default: 0. |
h | Height | Target height in pixels. | Integer. |
l | Longer side | Target length of the longer side. | Integer. |
s | Shorter side | Target length of the shorter side. | Integer. |
fw and fh | Fixed width and height | Target width and height to which you want to resize the image. | Integer. |
p | Percentage | Target size as a percentage of the original dimensions. The aspect ratio is preserved. | Integer, [0, 100]. |
Examples
All examples use image_process=resize as the query parameter to apply the resize action.
| Scenario | Example URL |
|---|---|
| Scale to 80% of the original size | example.com/image01.png?image_process=resize,p_80 |
| Scale only if the file is at least 1,024,000 bytes | example.com/image01.png?image_process=resize,l_200/threshold,1024000 |
| Scale by longer side (200 px) | example.com/image01.png?image_process=resize,l_200 |
| Scale by shorter side (200 px) | example.com/image01.png?image_process=resize,s_200 |
| Scale by width (200 px) | example.com/image01.png?image_process=resize,w_200 |
| Scale by height (200 px) | example.com/image01.png?image_process=resize,h_200 |
| Scale to exact width and height (200 x 200 px) | example.com/image01.png?image_process=resize,fw_200,fh_200 |
In the conditional resize example, threshold specifies the minimum file size in bytes. The image is resized only when its file size meets or exceeds the threshold. Adjust the value to match your requirements.