Rotate an image stored in OSS clockwise by appending the rotate parameter to the image URL or processing action.
Parameters
Operation: rotate
| Parameter | Description | Valid values |
|---|---|---|
[value] | Degrees to rotate the image clockwise | [0, 360]; default: 0 (no rotation) |
Usage notes
Non-right-angle rotation increases image size. When the rotation angle is not a multiple of 90° (such as 45° or 70°), the size of the processed image increases.
Maximum image size: The source image cannot exceed 4096 × 4096 pixels.
Animated GIF images become static. Applying rotation to an animated GIF converts it to a static GIF. This is by design — rotating every frame of a large animated GIF would require substantial memory and processing time.
Rotate public-read or public-read-write images
For images with public-read or public-read-write ACL, append the x-oss-process query parameter to the image URL.
The following examples use this source image:
https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg

Rotate 90° clockwise
https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/rotate,90
Rotate 70° clockwise
https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/rotate,70
Rotate private images
For private images, use the OSS SDKs or RESTful API to sign the request and apply the rotation.
Use OSS SDKs
All SDK examples below use image/rotate,90 as the process string and save the result to a local file. For other programming languages, see SDK references.
Java
Requires OSS SDK for Java 3.17.4 or later.
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GetObjectRequest;
import java.io.File;
public class Demo {
public static void main(String[] args) throws Throwable {
// In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou.
String region = "cn-hangzhou";
// 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 name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the full path of the source object. Do not include the bucket name in the full path.
String objectName = "example.jpg";
// Specify the local path for the processed image. If a file with the same name already exists, it is overwritten.
String pathName = "D:\\dest.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Rotate the source image by 90 degrees clockwise.
String image = "image/rotate,90";
GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
request.setProcess(image);
ossClient.getObject(request, new File(pathName));
} 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
Requires OSS SDK for Python 2.18.4 or later.
# -*- 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 endpoint of the region in which the bucket is located.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the ID of the Alibaba Cloud region in which the bucket is located.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# Specify the name of the source object. If the object is not in the root directory of the bucket,
# include the full path. Example: exampledir/src.gif.
key = 'example.jpg'
# Specify the local path for the processed image.
new_pic = 'D:\\dest.jpg'
# Rotate the source image by 90 degrees clockwise.
image = 'image/rotate,90'
bucket.get_object_to_file(key, new_pic, process=image)Go
Requires OSS SDK for Go 3.0.2 or later.
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)
}
// Specify the endpoint of the region in which the bucket is located.
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
if err != nil {
HandleError(err)
}
// Specify the name of the bucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
HandleError(err)
}
// Specify the name of the source object. If the object is not in the root directory of the bucket,
// include the full path. Example: exampledir/src.gif.
sourceImageName := "example.jpg"
// Specify the local path for the processed image.
targetImageName := "D://dest.jpg"
// Rotate the source image by 90 degrees clockwise.
image := "image/rotate,90"
err = bucket.GetObjectToFile(sourceImageName, targetImageName, oss.Process(image))
if err != nil {
HandleError(err)
}
}PHP
Requires OSS SDK for PHP 2.7.0 or later.
<?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();
// Specify the endpoint of the region in which the bucket is located.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket.
$bucket = "examplebucket";
// Specify the full path of the source object. Do not include the bucket name in the full path.
$object = "example.jpg";
// Specify the local path for the processed image.
$download_file = "D:\\dest.jpg";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Rotate the source image by 90 degrees clockwise.
$image = "image/rotate,90";
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
OssClient::OSS_PROCESS => $image
);
$ossClient->getObject($bucket, $object, $options);Use the RESTful API
To call the API directly, include a V4 signature in the request. For details, see (Recommended) Include a V4 signature.
GET /oss.jpg?x-oss-process=image/rotate,90 HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e