Alibaba Cloud OSS Image Processing (IMG) allows you to process image objects uploaded to OSS. This topic describes how to resize images.

Parameters

Operation: resize

  • Resize an image based on the specified height and width
    Parameter Description Value range
    m Specifies the resize type:
    • lfit: resizes the source image proportionally as large as possible within a rectangle based on the specified width and height.
    • mfit: resizes the source image proportionally as small as possible beyond a rectangle based on the specified width and height.
    • fill: crops the source image to the specified width and height.
    • pad: resizes the source image based on the specified width and height, and fills empty space.
    • fixed: forcibly resizes the source image based on the specified width and height.
    lfit, mfit, fill, pad, and fixed. Default value: lfit.
    w Specifies the width of the target thumbnail. 1~4096
    h Specifies the height of the target thumbnail. 1~4096
    l Specifies the dimension of the longer side of the target thumbnail. 1~4096
    s Specifies the dimension of the shorter side of the target thumbnail. 1~4096
    limit Specifies whether to process the target thumbnail when it is larger than the source image. 1 indicates that the thumbnail is not processed. 0 indicates that the thumbnail is processed. 0 and 1. Default value: 1.
    color When you set the resize type to pad, you can select a color to fill empty space. The default color is white. Hexadecimal color codes are used. For example, 00FF00 indicates green. [000000~FFFFFF]
  • Resize proportionally
    Parameter Description Value range
    p The percentage. A percentage smaller than 100 indicates that the image is scaled down. A percentage greater than 100 indicates that the image is scaled up. 1~1000

Instructions

  • Source image:
    • Only JPG, PNG, BMP, GIF, WebP, and TIFF images are supported. GIF images can be resized based on the specified width and height. Proportional resizing is not supported. GIF images become static images when you resize images proportionally.
    • The object size cannot exceed 20 MB.
    • Each side of the image cannot exceed 30,000 pixels.
    • The source image cannot exceed 250 million pixels in total.
  • Thumbnail: The area of the target thumbnail cannot exceed 4096 × 4096 pixels in size, and neither size can be greater than 4,096 pixels.
  • Longer side and shorter side: Longer side refers to the side with a larger ratio of original size to target size, and shorter side refers to the side with a smaller ratio of original size to target size. For example, if a source image is resized from 400 × 200 pixels to 800 × 100 pixels, the original-to-target ratios are 0.5 (400/800) and 2 (200/100). Given that 0.5 is smaller than 2, the 200-pixel side is the longer side and the 400-pixel side the shorter one.
  • By default, when the width or height of a thumbnail is specified, the source image is resized proportionally on a single side. In the fixed width and height mode, the source image is resized by holding the width or height constant.
  • If only the width or height of a thumbnail is specified, the source image is returned in its original format. If you want to save the image in other formats, see Quality transformation and Format conversion.
  • By default, if resize is called, the source image cannot be scaled up. If the requested image is larger than the source image, the source image is returned. If you want to scale up the image, add the limit_0 parameter to the request. Example: https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/resize,w_500,limit_0.

Examples

SDK examples for various programming languages