All Products
Search
Document Center

Object Storage Service:Image scaling

Last Updated:Sep 06, 2025

You can scale an image up or down by adding image scaling parameters to a GetObject request.

Scenarios

  • Web design: Adapt images to different screen sizes and resolutions for web and mobile app development.

  • Social media: Process user-uploaded images of various sizes into standard preview dimensions.

  • Image recognition and analysis: Scale images to improve processing efficiency in computer vision and machine learning.

Limits

Limit

Item

Description

Source image limits

Image format

Source images can be in JPG, PNG, BMP, GIF, WebP, TIFF, or HEIC format.

Image size

A source image cannot exceed 20 MB in size. To adjust the source image size limit, submit a request in Quota Center.

Image dimensions

The width or height of the source image cannot exceed 30,000 px. The total number of pixels cannot exceed 250 million.

Note

For animated images, such as GIFs, the total number of pixels is calculated as width × height × number of frames. For static images, such as PNGs, the total number of pixels is calculated as width × height.

Scaled image limits

Image scaling

The width or height of the scaled image cannot exceed 16,384 px. The total number of pixels cannot exceed 16,777,216.

Methods

When you include the ?x-oss-process=image/resize,parame_value parameter in a request, OSS processes the image in real time and returns the result. image/resize specifies the scaling operation. parame is a supported scaling parameter, and value is the value of the parameter. For more information about the parameters, see Parameters. You can use multiple parameters together.

For public-read images, you can add processing parameters to the image URL to allow permanent anonymous access. For private images, you can call an SDK with signature information or an API to process the image.

Public-read images

The following table describes how to add the ?x-oss-process=image/resize,parame_value parameter to the URL of a public-read image. Replace parame_value with the specific parameters and values that you need.

Original image URL

Image URL with processing parameters

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,p_50

Private images

You can use an OSS SDK to generate a signed URL with image scaling parameters. This grants users temporary access to the processed image. The following examples show how to generate a signed URL with the ?x-oss-process=image/parame_value parameter for a private image:

Java

package com.aliyun.oss.demo;
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import java.net.URL;
import java.util.Date;

public class Demo {
    public static void main(String[] args) throws Throwable {
        // Set the endpoint. In this example, the China (Hangzhou) region is used. Specify the actual endpoint.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the bucket name, for example, examplebucket.
        String bucketName = "examplebucket";
        // Specify the full path of the object. If the image is not in the root directory of the bucket, include the full path, for example, exampledir/exampleobject.jpg.
        String objectName = "exampledir/exampleobject.png";
        // Specify the region where the bucket is located. In this example, the China (Hangzhou) region is used. Set Region to cn-hangzhou.
        String region = "cn-hangzhou";

        // Create an OSSClient instance.
        // When the OSSClient instance is no longer used, call the shutdown method to release resources.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {
            // Scale the image. Replace parame_value with a specific parameter and value. For example, p_50 indicates that the image is proportionally scaled down to 50% of its original size.
            String style = "image/resize,parame_value";
            // Set the expiration time of the signed URL to 3,600 seconds.
            Date expiration = new Date(new Date().getTime() + 3600 );
            GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET);
            req.setExpiration(expiration);
            req.setProcess(style);
            URL signedUrl = ossClient.generatePresignedUrl(req);
            System.out.println(signedUrl);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

Python

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the bucket name.
bucket = 'examplebucket'

# Specify the endpoint of the region where the bucket is located. In this example, the China (Hangzhou) region is used.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'

# Specify the general-purpose region ID of Alibaba Cloud.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, bucket, region=region)

# Specify the name of the source image. If the image is not in the root directory of the bucket, include the full path, for example, exampledir/exampleobject.jpg.
key = 'exampledir/exampleobject.png'

# Specify the expiration time in seconds.
expire_time = 3600

# Scale the image. Replace parame_value with a specific parameter and value. For example, p_50 indicates that the image is proportionally scaled down to 50% of its original size.
image_process = 'image/resize,parame_value'

# Generate a signed URL that contains image processing parameters.
url = bucket.sign_url('GET', key, expire_time, params={'x-oss-process': image_process}, slash_safe=True)

# Print the signed URL.
print(url)

PHP

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;

// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// Set yourEndpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "yourEndpoint";
// Specify the bucket name, for example, examplebucket.
$bucket= "examplebucket";
// Specify the full path of the object, for example, exampledir/exampleobject.jpg. The full path cannot contain the bucket name.
$object = "exampledir/exampleobject.jpg";

$config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        "region"=> "cn-hangzhou"
    );
    $ossClient = new OssClient($config);

// Generate a signed URL that contains image processing parameters. The URL is valid for 3,600 seconds and can be accessed in a browser.
$timeout = 3600;

$options = array(
    // Scale the image. Replace parame_value with a specific parameter and value. For example, p_50 indicates that the image is proportionally scaled down to 50% of its original size.
    OssClient::OSS_PROCESS => "image/resize,parame_value");

$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options);
print("rtmp url: \n" . $signedUrl);

Go

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func HandleError(err error) {
	fmt.Println("Error:", err)
	os.Exit(-1)
}

func main() {
	// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Create an OSSClient instance.
	// Set yourEndpoint to the endpoint of the bucket. In this example, the China (Hangzhou) region is used. Set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify the actual endpoint for other regions.
	// Set yourRegion to the region where the bucket is located. In this example, the China (Hangzhou) region is used. Set the region to cn-hangzhou. Specify the actual region for other regions.
	clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
	clientOptions = append(clientOptions, oss.Region("yourRegion"))
	// Set the signature version.
	clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
	client, err := oss.New("yourEndpoint", "", "", clientOptions...)
	if err != nil {
		HandleError(err)
	}

	// Specify the name of the bucket where the image is stored, for example, examplebucket.
	bucketName := "examplebucket"
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		HandleError(err)
	}
	// Specify the name of the image. If the image is not in the root directory of the bucket, include the full path, for example, exampledir/exampleobject.jpg.
	ossImageName := "exampledir/exampleobject.png"
	// Generate a signed URL and set the expiration time to 3,600s. The maximum validity period is 32,400 seconds.
	// Scale the image. Replace parame_value with a specific parameter and value. For example, p_50 indicates that the image is proportionally scaled down to 50% of its original size.
	signedURL, err := bucket.SignURL(ossImageName, oss.HTTPGet, 3600, oss.Process("image/resize,parame_value"))
	if err != nil {
		HandleError(err)
	} else {
		fmt.Println(signedURL)
	}
}

The following is an example of a generated signed URL:

https://examplebucket.oss-cn-hangzhou.aliyuncs.com/exampledir/exampleobject.png?x-oss-process=image%2Fresize%2Cp_50&x-oss-date=20241111T113707Z&x-oss-expires=3600&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-credential=LTAI********************%2F20241111%2Fcn-hangzhou%2Foss%2Faliyun_v4_request&x-oss-signature=6fd07a2ba50bf6891474dc56aed976b556b6fbcd901cfd01bcde5399bf4802cb

For more information about how to use other SDKs to scale images, see SDK overview.

Parameters

Action: resize

Proportional scaling

You can use the p parameter to specify the percentage for proportional scaling.

Parameter

Description

Value

p

Scales the image by percentage.

[1,1000]

A value less than 100 scales down the image. A value greater than 100 scales up the image.

Note

This type of proportional scaling is not supported for animated images.

Scaling by specified dimensions

You can use the w and h parameters to specify the width and height. You can use the m parameter to control the scaling mode for different layouts. To control the longer or shorter edge of the scaled image, you can use the l or s parameter. To scale up an image, you must add the limit_0 parameter.

Parameter

Description

Value

w

The width of the scaled image.

[1,16384]

h

The height of the scaled image.

[1,16384]

m

The scaling mode.

  • lfit (default): Scales the image proportionally to fit within the specified width and height.

  • mfit: Scales the image proportionally to cover the specified width and height.

  • fill: Scales the image proportionally to cover the specified width and height, and then crops the image from the center.

  • pad: Scales the image proportionally to fit within the specified width and height, and then pads the image with a color to meet the specified dimensions.

  • fixed: Forces the image to be scaled to the specified width and height.

For more information about the images that are obtained after you scale an image in different modes, see Scaling calculation methods.

Note

If you set the scaling mode m to any value and specify the w or h of the target image, the l or s setting does not take effect.

l

The longer edge of the scaled image.

Note

The longer edge is the greater of the width and height. For example, if the source image is 100 px × 200 px, the longer edge is 200 px and the shorter edge is 100 px.

[1,16384]

s

The shorter edge of the scaled image.

[1,16384]

limit

Specifies whether to scale the image if the resolution of the target image is higher than the resolution of the source image.

Important

By default, if the target image is larger than the source image, the source image is returned. To scale up the image, you must add the limit_0 parameter.

  • 1 (default): Returns an image converted based on the resolution of the source image. The size of the returned image may be different from the size of the source image.

  • 0: Scales the image based on the specified parameters.

Note

For animated images, you can only scale them down by specifying the width and height. Proportional scaling down and scaling up are not supported.

color

The color for padding when the scaling mode is set to pad.

An RGB color value. Example: 000000 for black and FFFFFF for white.

Default value: FFFFFF (white)

Note
  • If you specify only the width or height for scaling:

    • If the scaling mode is `lfit`, `mfit`, or `fixed`, the image is scaled proportionally. For example, if the source image is 256 px × 144 px and you scale the height to 100 px, the width is scaled to 178 px.

    • If the scaling mode is `pad` or `fill`, the image is scaled to the specified dimensions. For example, if the source image is 256 px × 144 px and you scale the height to 100 px, the width is also scaled to 100 px.

  • If you specify only the l or s parameter, the image is scaled based on the specified edge, and the other edge is automatically adjusted based on the aspect ratio of the source image. In this case, the m parameter does not take effect.

  • If you specify both the l and s parameters, the image is scaled while maintaining the aspect ratio. In this case, the m parameter takes effect. If you do not specify a scaling mode, the default lfit mode is used.

Scaling calculation methods

Source image size

Scaling parameters

Scaling mode

Scaled image size

200 px × 100 px

150 px × 80 px

lfit (default)

Proportionally scales the image to the maximum size that fits within the rectangle of the specified width and height.

150 px × 75 px

lfit

mfit

Proportionally scales the image to the minimum size that extends beyond the rectangle of the specified width and height.

160 px × 80 px

mfit

fill

Proportionally scales the image to the minimum size that extends beyond the rectangle of the specified width and height, and then crops the image to the specified dimensions.

150 px × 80 px

fill

pad

Proportionally scales the image to the maximum size that fits within the rectangle of the specified width and height, and then pads the image with a color to meet the specified dimensions.

150 px × 80 px

pad

fixed

Forces the image to be scaled to the specified width and height. If the aspect ratio is different from that of the source image, the image is distorted.

150 px × 80 px

fixed

Note

If the scaling mode is `lfit` or `mfit` and the ratio is a decimal, the value is rounded to the nearest integer.

Examples

Proportionally scale down an image

When you add ?x-oss-process=image/resize,p_{percentage} to the end of an image URL, OSS processes the image in real time, proportionally scales it down by the specified percentage, and returns the result. image/resize specifies the scaling operation. p specifies scaling by percentage. If the value of p is in the range of [1, 100], the image is scaled down. The value of p must be a positive integer.

Example

The following example shows how to use ?x-oss-process=image/resize,p_50 to scale down an image to 50% of its original size:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,p_50

Image dimensions

2500 × 1875 px

1250 × 938 px

Proportionally scale up an image

When you add ?x-oss-process=image/resize,p_{percentage} to the end of an image URL, OSS processes the image in real time, proportionally scales it by the specified percentage, and returns the result. image/resize specifies the scaling operation. p specifies scaling by percentage. If the value of p is in the range of [100, 1000], the image is scaled up. The value of p must be a positive integer.

Example

The following example shows how to use ?x-oss-process=image/resize,p_120 to scale up an image to 120% of its original size:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,p_120

Image dimensions

2500 × 1875 px

3000 × 2250 px

Scale down an image to a fixed width with an adaptive height

When you add ?x-oss-process=image/resize,w_{width} to the end of an image URL, OSS processes the image in real time, proportionally scales it down to the specified width, and returns the result. image/resize specifies the scaling operation. w specifies the target width of the image. The value of w must be in the range of [1,16384]. The value of w must be a positive integer.

Example

The following example shows how to use ?x-oss-process=image/resize,w_200 to scale down an image to a fixed width of 200 pixels with an adaptive height:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL:https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,w_200

Image dimensions

2500 × 1875 px

200 × 150 px

Scale up an image to a fixed width with an adaptive height

When you add ?x-oss-process=image/resize,w_{width} to the end of an image URL, OSS processes the image in real time, proportionally scales it to the specified width, and returns the result. image/resize specifies the scaling operation. w specifies the target width of the image. The value of w must be in the range of [1,16384]. The value of w must be a positive integer.

Important

By default, if the target image is larger than the source image, the source image is returned. To scale up the image, you must add the limit_0 parameter.

Example

The following example shows how to use ?x-oss-process=image/resize,w_3000,limit_0 to scale up an image to a fixed width of 3,000 pixels with an adaptive height:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL:https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,w_3000,limit_0

Image dimensions

2500 × 1875 px

3000 × 2250 px

Scale down an image to a fixed height with an adaptive width

When you add ?x-oss-process=image/resize,h_{height} to the end of an image URL, OSS processes the image in real time, proportionally scales it to the specified height, and returns the result. image/resize specifies the scaling operation. h specifies the target height of the image. The value of h must be in the range of [1,16384]. The value of h must be a positive integer.

Example

The following example shows how to use ?x-oss-process=image/resize,h_100 to scale down an image to a fixed height of 100 pixels with an adaptive width:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL:https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,h_100

Image dimensions

2500 × 1875 px

133 × 100 px

Scale up an image to a fixed height with an adaptive width

When you add ?x-oss-process=image/resize,h_{height} to the end of an image URL, OSS processes the image in real time, proportionally scales it to the specified height, and returns the result. image/resize specifies the scaling operation. h specifies the target height of the image. The value of h must be in the range of [1,16384]. The value of h must be a positive integer.

Important

By default, if the target image is larger than the source image, the source image is returned. To scale up the image, you must add the limit_0 parameter.

Example

The following example shows how to use ?x-oss-process=image/resize,h_2000,limit_0 to scale up an image to a fixed height of 2,000 pixels with an adaptive width:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL:https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,h_2000,limit_0

Image dimensions

2500 × 1875 px

2667 × 2000 px

Scale an image to a fixed longer edge with an adaptive shorter edge

The image is scaled based on the specified longer edge, and the shorter edge is automatically adjusted based on the aspect ratio of the source image. In this case, the scaling mode m parameter does not take effect.

When you add image/resize,l_{length} to the end of an image URL, OSS processes the image in real time, proportionally scales it based on the longer edge, and returns the result. image/resize specifies the scaling operation. l specifies the longer edge. The value of l must be in the range of [1,16384]. The value of l must be a positive integer.

Important

By default, if the target image is larger than the source image, the source image is returned. To scale up the image, you must add the limit_0 parameter.

Example

The following example shows how to use ?x-oss-process=image/resize,l_200 to scale an image to a fixed longer edge of 200 pixels with an adaptive shorter edge:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL:https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,l_200

Image dimensions

2500 × 1875 px

200 × 150 px

Scale an image to a fixed shorter edge with an adaptive longer edge

The image is scaled based on the specified shorter edge, and the other edge is automatically adjusted based on the aspect ratio of the source image. In this case, the scaling mode m parameter does not take effect.

When you add image/resize,s_{length} to the end of an image URL, OSS processes the image in real time, proportionally scales it based on the shorter edge, and returns the result. image/resize specifies the scaling operation. s specifies the shorter edge. The value of s must be in the range of [1,16384]. The value of s must be a positive integer.

Important

By default, if the target image is larger than the source image, the source image is returned. To scale up the image, you must add the limit_0 parameter.

Example

The following example shows how to use ?x-oss-process=image/resize,s_200,limit_0 to scale an image to a fixed shorter edge of 200 pixels with an adaptive longer edge:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

Processed image URL:https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,s_200

Image dimensions

2500 × 1875 px

267 × 200 px

Scale and pad an image to fixed dimensions

Scaling and padding an image adjusts the image to the specified width and height while maintaining the aspect ratio.

When you add image/resize,m_pad,w_{width},h_{height},color_{RGB} to the end of an image URL, OSS processes the image in real time and returns the result. image/resize specifies the scaling operation. m_pad scales the image to the maximum size that fits within the rectangle of the specified width and height. color specifies the color to fill the blank space. If you do not set this parameter, the blank space is filled with white. w specifies the target width of the image. h specifies the target height of the image. The values of w and h must be in the range of [1,16384]. The values of w and h must be positive integers.

Example

The following example shows how to use ?x-oss-process=image/resize,m_pad,w_100,h_100 to scale and pad an image to a fixed width and height of 100 pixels:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,m_pad,w_100,h_100

Image dimensions

2500 × 1875 px

100 × 100 px

The following example shows how to use ?x-oss-process=image/resize,m_pad,w_100,h_100,color_FF0000 to scale and pad an image to a fixed width and height of 100 pixels with red as the padding color:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,m_pad,w_100,h_100,color_FF0000

Image dimensions

2500 × 1875 px

100 × 100 px

Scale and crop an image from the center to fixed dimensions

Scaling and cropping from the center proportionally scales an image to fill the target dimensions. If the aspect ratio of the source image is different from the target dimensions, the excess parts of the image are cropped from the center.

When you add image/resize,m_fill,w_{width},h_{height} to the end of an image URL, OSS processes the image in real time, scales it to the specified width and height, and returns the result. image/resize specifies the scaling operation. m_fill proportionally scales the image to the minimum size that extends beyond the rectangle of the specified width and height. The excess part is cropped from the center. w specifies the target width of the image. h specifies the target height of the image. The values of w and h must be in the range of [1,16384]. The values of w and h must be positive integers.

Example

The following example shows how to use ?x-oss-process=image/resize,m_fill,w_100,h_100 to scale and crop an image from the center to a fixed width and height of 100 pixels:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,m_fill,w_100,h_100

Image dimensions

2500 × 1875 px

100 × 100 px

Force-scale an image to fixed dimensions

Force-scaling an image to fixed dimensions adjusts the image to the specified width and height, regardless of the aspect ratio of the source image. This method may distort the image because the image is stretched or compressed to fit the new dimensions.

When you add image/resize,m_fixed,w_{width},h_{height} to the end of an image URL, OSS processes the image in real time, force-scales it to the specified width and height, and returns the result. image/resize specifies the scaling operation. m_fixed specifies that the image is force-scaled. w specifies the target width of the image. h specifies the target height of the image. The values of w and h must be in the range of [1,16384]. The values of w and h must be positive integers.

Example

The following example shows how to use ?x-oss-process=image/resize,m_fixed,w_100,h_100 to force-scale an image to a fixed width and height of 100 pixels:

Item

Source image

Processed image

Image preview

image

image

URL

Source image URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,m_fixed,w_100,h_100

Image dimensions

2500 × 1875 px

100 × 100 px

Billing

When you resize images, the following fees are incurred. For pricing details of billable items, see OSS Pricing.

  • API

    Billable item

    Description

    GetObject

    GET requests

    You are charged request fees based on the number of successful requests.

    Outbound traffic over the Internet

    If you call the GetObject operation by using a public endpoint, such as oss-cn-hangzhou.aliyuncs.com, or an acceleration endpoint, such as oss-accelerate.aliyuncs.com, you are charged fees for outbound traffic over the Internet based on the data size.

    Retrieval of IA objects

    If IA objects are retrieved, you are charged IA data retrieval fees based on the size of the retrieved IA data.

    Retrieval of Archive objects in a bucket for which real-time access is enabled

    If you retrieve Archive objects in a bucket for which real-time access is enabled, you are charged Archive data retrieval fees based on the size of retrieved Archive objects.

    Transfer acceleration fees

    If you enable transfer acceleration and use an acceleration endpoint to access your bucket, you are charged transfer acceleration fees based on the data size.

Related API operations

If your application has high custom requirements, you can directly call REST APIs. This requires you to manually write code to calculate signatures. For more information about how to calculate the Authorization header for public requests, see Signature V4 (recommended).

You can process images by adding image scaling parameters to the GetObject operation. For more information, see GetObject.

GET /oss.jpg?x-oss-process=image/resize,p_50 HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: SignatureValue

FAQ

What do I do if the image scaling parameters do not take effect?

Check whether you are using a CDN accelerated domain name and confirm whether the Ignore Parameters feature is disabled for caching. If you enable the Filter Parameters option for CDN, all query parameters after the question mark (?) in the file URL are removed. As a result, the original file without parameters, such as example.jpg, is accessed directly. To ensure correct caching and access, disable the Ignore Parameters feature for CDN. For more information, see Ignore parameters. However, if you disable this feature, URLs with different parameters are considered separate requests. This may increase the frequency of back-to-origin requests to OSS and reduce cache efficiency.

What do I do if scaling up an image by width and height does not take effect?

When you scale up an image by width and height, you must set the limit parameter to 0. Otherwise, the scaling operation does not take effect.

Example: In the following URL, the height of the image is scaled up from 1,875 px to 2,000 px.

https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/resize,h_2000,limit_0

How do I persistently store processed images?

OSS generates images in real time based on request parameters. By default, processed images are not saved. For scenarios where you frequently need to display the same processed result, such as thumbnails, cropped images, or format-converted images, you can use the image processing persistence feature of OSS. You can add a parameter to save the processed image to a specified bucket. For more information, see Image processing persistence.

How do I access a scaled image that is private?

You must sign the image URL to access the image. For more information, see How to obtain the access URL after an object is uploaded.

Is the outbound traffic fee for a request to access a scaled image calculated based on the size of the source image or the scaled image?

The outbound traffic fee for a request to access a scaled image is calculated based on the size of the scaled image. For example, if the source image is 20 MB and the scaled image is 2 MB, the traffic fee is calculated based on 2 MB.

What do I do if an error occurs when I decode a source WebP image?

A WebP decoding error may occur because the image is an animated image. You can to enable the WebP animated image decoding feature.