Object Storage Service (OSS) içinde depolanan bir dikdörtgen görüntünün köşelerini yuvarlatmak için rounded-corners işlemini kullanabilirsiniz. Bu konu, rounded-corners işleminin parametresini açıklar ve bir dikdörtgen görüntünün köşelerinin nasıl yuvarlatılacağına ilişkin örnekler sunar.
Parametreler
İşlem adı: rounded-corners
Aşağıdaki tabloda yapılandırabileceğiniz parametre açıklanmaktadır.
|
|
|
|
|
|
|
|
Kullanım notları
Görüntünün son biçimi (PNG, WebP veya BMP) alfa kanallarını destekliyorsa, yuvarlatılmış dikdörtgenin dışındaki alanlar şeffaf hale gelir. Görüntünün son biçimi JPG ise, yuvarlatılmış dikdörtgenin dışındaki alanlar beyaz olur. İşlenmiş görüntüyü PNG biçiminde kaydetmenizi öneririz.
Yuvarlatılmış köşeler için belirtilen yarıçap, kaynak görüntünün en büyük iç teğet çemberinin yarıçapından büyükse, köşeleri yuvarlatmak amacıyla kaynak görüntünün en büyük iç teğet çemberinin yarıçapı kullanılır. Bu durumda köşe yarıçapı, kaynak görüntünün en kısa kenarının yarısına eşit olur.
rounded-cornersişlemi GIF görüntüler için desteklenmez.
Yöntemler
Genel okuma veya genel okuma-yazma iznine sahip bir görüntünün köşelerini yuvarlatın
Bu bölümde, Çin (Hangzhou) bölgesindeki oss-console-img-demo-cn-hangzhou paketinde bulunan bir görüntünün köşelerinin nasıl yuvarlatılacağına ilişkin örnekler sunulmaktadır. Görüntü aşağıdaki URL'de barındırılmaktadır:
https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg
-
Kaynak görüntünün köşelerini yuvarlatın.
Parametreleri aşağıdaki gereksinimlere göre yapılandırın:
Köşelerin yuvarlatılacağı yarıçapı 30 piksel olarak ayarlayın:
rounded-corners,r_30.İşlenmiş görüntüyü JPG biçiminde kaydedin:
format,jpg. Kaynak görüntünün biçimi JPG ise bu parametreyi belirtmeyebilirsiniz.
Önceki parametrelerin uygulanmasında kullanılan URL şudur: https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/rounded-corners,r_30

-
Kaynak görüntüyü kırpın, kırpılan görüntünün köşelerini yuvarlatın ve işlenmiş görüntüyü PNG biçiminde kaydedin.
Parametreleri aşağıdaki gereksinimlere göre yapılandırın:
Kaynak görüntüyü varsayılan başlangıç konumundan 100 × 100 piksel boyutunda kırpın:
crop,w_100,h_100.Köşelerin yuvarlatılacağı yarıçapı 10 piksel olarak ayarlayın:
rounded-corners,r_10.İşlenmiş görüntüyü PNG biçiminde kaydedin:
format,png.
Önceki parametrelerin uygulanmasında kullanılan URL şudur: https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/crop,w_100,h_100/rounded-corners,r_10/format,png

Özel bir görüntünün köşelerini yuvarlatın
Özel bir görüntünün köşelerini yuvarlatmak için OSS SDK'larını ve RESTful API'yi kullanabilirsiniz.
OSS SDK'larını kullanın
Aşağıdaki kod, yaygın programlama dilleri için OSS SDK'larının özel bir görüntünün köşelerini yuvarlamak üzere nasıl kullanılacağına ilişkin örnekler sunar. Diğer programlama dillerini kullanarak görüntülerin köşelerini yuvarlatma hakkında daha fazla bilgi için bkz. Genel Bakış.
Java
Java için OSS SDK V3.17.4 veya sonraki bir sürüm gereklidir.
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 region in which the bucket is located. Example: cn-hangzhou.
String region = "cn-hangzhou";
// Obtain access credentials from environment variables. Before you execute 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 object. Do not include the bucket name in the full path.
String objectName = "example.jpg";
// Specify the full path of the processed image. Example: D:\\dest.jpg. If a file that has the same name already exists, the downloaded object overwrites the file. Otherwise, the downloaded object is saved in the path.
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 {
// Set the radius at which the corners are rounded to 30 pixels
String image = "image/rounded-corners,r_30";
GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
request.setProcess(image);
// Set the name of the processed image to dest.jpg and save it to your local computer.
// If you specify only the name of the processed image such as dest.jpg without specifying the local path, the processed image is saved to the local path of the project to which the sample program belongs.
ossClient.getObject(request, new File("D:\\dest.jpg"));
} 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();
}
}
}
}
PHP
PHP için OSS SDK V2.7.0 veya sonraki bir sürüm gereklidir.
<?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 execute 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. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
$bucket= "examplebucket";
// Specify the full path of the object. Do not include the bucket name in the full path.
$object = "example.jpg";
// Specify the full path of the processed image. Example: D:\\dest.jpg. If an image that has the same name already exists in the path, the processed image overwrites the image. Otherwise, the processed image is saved in the path.
// If you specify only the name of the processed image such as dest.jpg without specifying the local path, the processed image is saved to the local path of the project to which the sample program belongs.
$download_file = "D:\\dest.jpg";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
// Specify the ID of the Alibaba Cloud region in which the bucket is located.
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Set the radius at which the corners are rounded to 30 pixels.
$image = "image/rounded-corners,r_30";
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
OssClient::OSS_PROCESS => $image);
// Save the processed image to your local computer.
$ossClient->getObject($bucket, $object, $options);
Python
Python için OSS SDK V2.18.4 veya sonraki bir sürüm gereklidir.
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from environment variables. Before you execute 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. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
# Specify the actual endpoint.
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 image that you want to process. If the image is not stored in the root directory of the bucket, you must include the full path of the image. Example: exampledir/src.gif.
key = 'example.jpg'
# Specify the name of the processed image.
new_pic = 'D:\\dest.jpg'
# Set the radius at which the corners are rounded to 30 pixels.
image = 'image/rounded-corners,r_30'
bucket.get_object_to_file(key, new_pic, process=image)
Go
Go için OSS SDK V3.0.2 veya sonraki bir sürüm gereklidir.
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 execute 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.
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify the actual endpoint.
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 in which the source image is stored. Example: examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
HandleError(err)
}
// Specify the name of the image that you want to process. If the image is not stored in the root directory of the bucket, you must include the full path of the image. Example: exampledir/src.gif.
sourceImageName := "example.jpg"
// Specify the name of the processed image.
targetImageName := "D://dest.jpg"
// Set the radius at which the corners are rounded to 30 pixels.
image := "image/rounded-corners,r_30"
err = bucket.GetObjectToFile(sourceImageName, targetImageName, oss.Process(image))
if err != nil {
HandleError(err)
}
}
RESTful API'yi kullanın
İşletmeniz yüksek düzeyde özelleştirme gerektiriyorsa doğrudan RESTful API'yi çağırabilirsiniz. Daha fazla bilgi için bkz. (Önerilen) V4 imzası ekleme.
GetObject işlemine görüntülerin köşelerini yuvarlatmak için parametreler ekleyebilirsiniz.
GET /oss.jpg?x-oss-process=image/rounded-corners,r_30 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