Use the circle parameter to crop an image stored in OSS into a circle. This is useful for generating profile pictures, user avatars, and circular thumbnails directly from images stored in Object Storage Service (OSS) — without preprocessing the image before upload.
For public images, append the processing parameter to the object URL. For private images, use an OSS SDK or the OSS API.
Parameters
Action: circle
| Parameter | Description | Valid value |
|---|---|---|
r | Radius of the circle, in pixels | 1–4096 |
Before you start
Output format controls background fill. The areas outside the circle are filled based on the output format:
| Output format | Background fill |
|---|---|
| PNG, WebP, BMP | Transparent |
| JPG | White |
To get a transparent background, save the result as PNG. Note that PNG files are larger than JPG files — consider this tradeoff in bandwidth-sensitive use cases.
Radius capping. If r exceeds half of the shorter side of the source image, OSS caps the effective radius: r = (shorter_side - 1) / 2. The output image dimensions are then r x 2 + 1 pixels on each side.
Crop a public image into a circle
For public-read or public-read-write images, append the x-oss-process query parameter directly to the object URL. No SDK or API call is required.
Source image (view):

Example 1: Circle with white fill (JPG)
Set r to 100 pixels. Areas outside the circle are white because the output format is JPG.
https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/circle,r_100
Example 2: Circle with transparent background (PNG)
Set r to 100 pixels and convert the output to PNG. Areas outside the circle are transparent.
https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/circle,r_100/format,png
Crop a private image into a circle
For private images, use an OSS SDK or the OSS API to sign the request and apply the circle parameter. All examples below use image/circle,r_100 as the process parameter string.
OSS SDKs
Python
Requires OSS SDK for Python 2.18.4 or later.
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Load access credentials from environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region where your bucket is located.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the region ID.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# Specify the source object name. Include the full path if the object is not in the root directory.
# Example: exampledir/src.jpg
key = 'example.jpg'
# Specify the local path to save the processed image.
new_pic = 'D:\\dest.jpg'
# Crop to a circle with radius 100 px. Areas outside the circle are white (JPG output).
image = 'image/circle,r_100'
bucket.get_object_to_file(key, new_pic, process=image)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 {
// Specify the endpoint of the region where your bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region ID. Example: cn-hangzhou.
String region = "cn-hangzhou";
// Load access credentials from environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name.
String bucketName = "examplebucket";
// Specify the object name (full path, excluding the bucket name).
String objectName = "example.jpg";
// Specify the local path to save the processed image.
String pathName = "D:\\dest.jpg";
// Create an OSSClient instance.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Crop to a circle with radius 100 px. Areas outside the circle are white (JPG output).
String image = "image/circle,r_100";
GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
request.setProcess(image);
ossClient.getObject(request, new File(pathName));
} catch (OSSException oe) {
System.out.println("OSSException: " + 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("ClientException: " + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}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() {
// Load access credentials from environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
HandleError(err)
}
// Specify the endpoint of the region where your 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 bucket name.
bucket, err := client.Bucket("examplebucket")
if err != nil {
HandleError(err)
}
// Specify the source object name. Include the full path if the object is not in the root directory.
sourceImageName := "example.jpg"
// Specify the local path to save the processed image.
targetImageName := "D://dest.jpg"
// Crop to a circle with radius 100 px. Areas outside the circle are white (JPG output).
image := "image/circle,r_100"
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;
// Load access credentials from environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint of the region where your bucket is located.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name.
$bucket = "examplebucket";
// Specify the object name (full path, excluding the bucket name).
$object = "example.jpg";
// Specify the local path to save 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);
// Crop to a circle with radius 100 px. Areas outside the circle are white (JPG output).
$image = "image/circle,r_100";
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
OssClient::OSS_PROCESS => $image
);
$ossClient->getObject($bucket, $object, $options);OSS API
For custom integrations that require direct API calls, use the GetObject operation and include x-oss-process as a query parameter. Your code must calculate the request signature. For details, see GetObject.
GET /oss.jpg?x-oss-process=image/circle,r_100 HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS qn6q**************:77Dv****************What's next
Chain circle crop with other image processing operations using the
|separator inx-oss-process. For example, crop to a square first usingcrop, then applycircle. See Image processing.Save the processed image permanently to OSS instead of returning it inline. See Save processed images.