Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Custom crop

Son Güncelleme:Oct 21, 2026

Genişlik, yükseklik, başlangıç koordinatları ve sabit nokta konumunu belirterek görüntüleri tam boyutlara kırpın.

Senaryolar

  • Web tasarımı: Görüntüleri avatarlar, arka planlar ve ürün galerileri gibi düzen öğelerine sığacak şekilde kırpmak için kullanın.

  • Sosyal medya görüntü teknik özellikleri: Farklı sosyal medya platformları; küçük resimler, gönderi görselleri ve hikaye görselleri dahil olmak üzere çeşitli görüntü türleri için belirli boyut gereksinimleri uygular. En iyi görsel sunumu sağlamak amacıyla görüntülerin önceden önerilen boyutlara kırpılması gerekir.

  • Mobil uygulama geliştirme: Uygulama simgelerini, açılış ekranlarını ve uygulama içi grafikleri farklı cihaz çözünürlükleriyle eşleşecek şekilde kırpın.

  • Görüntü veritabanı yönetimi: Kapsamlı görüntü depolarını sürdüren kütüphane ve arşivler gibi kuruluşlarda, kataloglama ve arşivleme iş akışları sırasında görüntü boyutlarını önceden tanımlanmış boyutlara kırpıp standartlaştırmak gerekir.

Kullanım notları

  • İşlenen görüntünün belirtilen genişliği ve yüksekliği 16.384 pikseli aşmamalıdır.

  • Başlangıç koordinatları kaynak görüntü sınırlarını aşıyorsa BadRequest hatası döndürülür: Advance cut's position is out of image.

  • Belirtilen genişlik ve yükseklik kaynak görüntü boyutlarını aşıyorsa kırpma alanı görüntü sınırlarıyla kısıtlanır.

Yöntemler

Görüntü işleme (IMG) parametrelerini yapılandırmak için nesne URL'lerini, OSS SDK'larını kullanabilir veya API operasyonlarını çağırabilirsiniz. Nesne URL'leri yalnızca genel olarak erişilebilir görüntüler (public-read veya public-read-write) için desteklenir. Özel görüntüler için OSS SDK'larını kullanın veya doğrudan API operasyonlarını çağırın. Daha fazla bilgi için bkz. Görüntü işleme yöntemleri .

public-read veya public-read-write görüntüleri kırpın

Görüntü ACL'si public-read veya public-read-write ise işlenen görüntüye erişmek için nesne URL'sine IMG parametreleri ekleyin.

Bu örnekte ?x-oss-process=image/crop,parame_value ifadesi genel okuma izinli bir görüntünün URL'sine eklenmiştir. parame_value değerini yalnızca Parametreler bölümünde açıklanan özel parametreler ve değerlerle değiştirmeniz yeterlidir. Gerektiğinde URL'ye birden çok parametre ekleyebilirsiniz.


Kaynak görüntünün URL'si


İşlenen görüntüye erişmek için kullanılan 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/crop,x_800,y_50

Özel görüntüleri kırpın

OSS SDK'larını kullanın

OSS SDK'larıyla özel bir görüntüyü kırpmaya yönelik örnek kod. Diğer programlama dilleri için bkz. Genel Bakış .

Java

OSS SDK for Java 3.17.4 veya sonraki bir sürüm gerekir.

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. 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 of 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 image. 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 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. 
        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 an area of 900 × 900 pixels in the lower-right corner of the image. 
            String image = "image/crop,w_900,h_900,g_se";
            GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
            request.setProcess(image);
            // Save the processed image 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

OSS SDK for PHP 2.7.0 veya sonraki bir sürüm gerekir.

<?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. 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 source image. Do not include the bucket name in the full path. 
$object = "src.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);

// Crop an area of 900 × 900 pixels in the lower-right corner of the image. 
$image = "image/crop,w_900,h_900,g_se";

$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

OSS SDK for Python 2.18.4 veya sonraki bir sürüm gerekir.

# -*- 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. 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 ID of the Alibaba Cloud region in which the bucket is located. 
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the source image is stored in the root directory of the bucket, you can specify only the image name. Example: source-example.jpg. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/source-example.jpg. 
key = 'source-example.jpg'

# Specify the full path of the processed image. Example: D:\\target-example.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. 
local_file_name = 'D:\\target-example.jpg'

# Configure the crop parameters to crop an area of 900 × 900 pixels in the lower-right corner of the image. 
process = 'image/crop,w_900,h_900,g_se'

# Use the get_object method and pass the processing instruction by using the process parameter. 
result = bucket.get_object_to_file(key, local_file_name, process=process)

Go

OSS SDK for Go 3.0.2 veya sonraki bir sürüm gerekir.

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. 
	// 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 your 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 source image. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/example.jpg. 
	sourceImageName := "example.jpg"
	// Specify the name of the processed image. 
	targetImageName := "D://dest.jpg"
	// Crop an area of 900 × 900 pixels in the lower-right corner of the image. 
	image := "image/crop,w_900,h_900,g_se"
	err = bucket.GetObjectToFile(sourceImageName, targetImageName, oss.Process(image))
	if err != nil {
		HandleError(err)
	}
}

OSS API'yi kullanın

Doğrudan RESTful API istekleri gönderebilirsiniz. İmza hesaplamasını kodunuza dahil edin. Authorization üst bilgisinin nasıl hesaplanacağı hakkında bilgi için bkz. (Önerilen) V4 imzası ekleme.

GetObject operasyonunda kırpma parametrelerini belirterek görüntüleri ihtiyacınız olan tam boyuta kırpabilirsiniz. Daha fazla bilgi için bkz. GetObject .

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

Parametreler

Eylem: crop

Aşağıdaki tabloda görüntü kırpma parametreleri açıklanmaktadır.

Parametre

Açıklama

Geçerli değer

w

Kırpmak istediğiniz alanın genişliği.

[0, görüntü genişliği]

Varsayılan değer: Maksimum değer.

h

Kırpmak istediğiniz alanın yüksekliği.

[0, görüntü yüksekliği]

Varsayılan değer: Maksimum değer.

x

Kırpmak istediğiniz alanın X koordinatı. Varsayılan değer, görüntünün sol üst köşesinin X koordinatıdır.

[0, görüntü genişliği]

y

Kırpmak istediğiniz alanın Y koordinatı. Varsayılan değer, görüntünün sol üst köşesinin Y koordinatıdır.

[0, görüntü yüksekliği]

g

3×3'lük bir ızgaradaki sabit nokta konumu. Görüntü dokuz parçaya bölünür ve kırpma alanı bu konumlardan biriyle hizalanır.

  • nw: sol üst

  • north: orta üst

  • ne: sağ üst

  • west: sol orta

  • center: merkez

  • east: sağ orta

  • sw: sol alt

  • south: orta alt

  • se: sağ alt

Her bir parçanın konumunun nasıl hesaplanacağı aşağıdaki tabloda gösterilmiştir.

ratio

Akıllı kırpma için en boy oranı parametresi. Biçim: ratio_width_height. Örneğin, ratio_1_1 1:1 kare kırpar ve ratio_16_9 16:9 geniş ekran kırpar.

Hem genişlik hem de yükseklik pozitif tamsayılardır.

Not

Bu parametre yalnızca g_auto ayarlandığında etkilidir. Ratio belirtildiğinde algoritma, akıllı şekilde algılanan konuyu koruyarak görüntüyü belirtilen en boy oranına göre kırpar.

Aşağıdaki tabloda parça konumlarının nasıl hesaplandığı gösterilmektedir. srcW kaynak görüntü genişliği ve srcH kaynak görüntü yüksekliğidir.


Parça


Hesaplama yöntemi


nw


0, 0


north


srcW/2 - w/2, 0


ne


srcW - w, 0


west


0, srcH/2 - h/2


center


srcW/2 - w/2, srcH/2 - h/2


east


srcW - w, srcH/2 - h/2


sw


0, srcH - h


south


srcW/2 - w/2, srcH - h


se


srcW - w, srcH - h

Örnekler

Belirli bir başlangıç noktasından kırpma

Bir görüntüyü (800, 50) başlangıç noktasından sınırlara kadar kırpın:

  • Eylemi belirtin: crop.

  • Başlangıç noktasını (800, 500) belirtin: x_800,y_500.

  • Sınırlara kadar kırpın: Kırpma için varsayılan olarak w ve h değerlerinin maksimumu kullanılır. Bu nedenle w ve h parametrelerini belirtmek isteğe bağlıdır.

public-read veya public-read-write iznine sahip bir görüntüyü kırpmak için görüntü URL'sine ?x-oss-process=image/crop,x_800,y_500 ifadesini ekleyin. OSS, istek üzerine kırpma işlemini dinamik olarak uygular ve işlenen görüntüyü döndürür. Özel bir görüntüyü nasıl kıracağınız hakkında bilgi için bkz. Özel görüntüleri kırpın .

Demo

Aşağıdaki örnekte, kaynak görüntünün URL'sine ?x-oss-process=image/crop,x_800,y_500 ifadesi eklenerek kaynak görüntünün (800, 50) başlangıç noktasından sınırlara kadar nasıl kırpıldığı açıklanmaktadır:


Kaynak görüntü


İşlenen görüntü

image

image


Kaynak görüntünün URL'si: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg


İşlenen görüntüye erişmek için kullanılan URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/crop,x_800,y_500

Belirli bir başlangıç noktasından belirtilen genişlik ve yüksekliğe göre bir alanı kırpma

(800, 500) başlangıç noktasından 300 × 300 piksellik bir alanı kırpın:

  • Eylemi belirtin: crop.

  • Başlangıç noktasını (800, 500) belirtin: x_800,y_500.

  • 300 × 300 piksellik bir alanı kırpın: w_300,h_300.

public-read veya public-read-write iznine sahip bir görüntüyü kırpmak için görüntü URL'sine ?x-oss-process=image/crop,x_800,y_500,w_300,h_300 ifadesini ekleyin. OSS, istek üzerine kırpma işlemini dinamik olarak uygular ve işlenen görüntüyü döndürür. Özel bir görüntüyü nasıl kıracağınız hakkında bilgi için bkz. Özel görüntüleri kırpın.

Örnek efekt

Aşağıdaki tabloda, kaynak görüntünün URL'sine ?x-oss-process=image/crop,x_800,y_500,w_300,h_300 ifadesi eklenerek belirtilen (800, 500) başlangıç noktasından 300 × 300 piksellik bir alanın çıkarılmasının etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

image

image


Kaynak görüntünün URL'si: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg


İşlenen görüntüye erişmek için kullanılan URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/crop,x_800,y_500,w_300,h_300

Bir görüntünün sağ alt köşesinde belirtilen genişlik ve yüksekliğe göre bir alanı kırpma

Bir görüntünün sağ alt köşesinde 900 × 900 piksellik bir alanı kırpın

  • Eylemi belirtin: crop.

  • Sağ alt köşedeki başlangıç noktasını belirtin: g_se.

  • 900 × 900 piksellik bir alanı kırpın: w_900,h_900.

public-read veya public-read-write iznine sahip bir görüntüyü kırpmak için görüntü URL'sine ?x-oss-process=image/crop,g_se,w_900,h_900 ifadesini ekleyin. OSS, istek üzerine kırpma işlemini dinamik olarak uygular ve işlenen görüntüyü döndürür. Özel bir görüntüyü nasıl kıracağınız hakkında bilgi için bkz. Özel görüntüleri kırpın.

Örnek efekt

Aşağıdaki tabloda, kaynak görüntünün URL'sine ?x-oss-process=image/crop,g_se,w_900,h_900 ifadesi eklenerek bir görüntünün sağ alt köşesinden 900 × 900 piksellik bir alanın kırpılmasının etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

image

image


Kaynak görüntünün URL'si: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg


İşlenen görüntüye erişmek için kullanılan URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/crop,g_se,w_900,h_900

Bir görüntünün sağ alt köşesinde belirtilen genişlik ve yüksekliğe göre bir alanı kırpma ve kırpılan alanı germe

Bir görüntünün sağ alt köşesinde 900 × 900 piksellik bir alanı kırpın ve kırpılan alanı (100.200) kadar aşağıya doğru gerin:

  • Eylemi belirtin: crop.

  • Görüntünün sağ alt köşesindeki başlangıç noktasını belirtin ve kırpılan alanı (100.200) kadar aşağıya doğru gerin: g_se,x_100,y_200

  • 900 × 900 piksellik bir alanı kırpın: w_900,h_900.

public-read veya public-read-write iznine sahip bir görüntüyü kırpmak için görüntü URL'sine ?x-oss-process=image/crop,g_se,x_100,y_200,w_900,h_900 ifadesini ekleyin. OSS, istek üzerine kırpma işlemini dinamik olarak uygular ve işlenen görüntüyü döndürür. Özel bir görüntüyü nasıl kıracağınız hakkında bilgi için bkz. Özel görüntüleri kırpın.

Örnek efekt

Aşağıdaki tabloda, kaynak görüntünün URL'sine ?x-oss-process=image/crop,g_se,x_100,y_200,w_900,h_900 ifadesi eklenerek bir görüntünün sağ alt köşesinde 900 × 900 piksellik bir alanın kırpılmasının etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

image

image


Kaynak görüntünün URL'si: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg


İşlenen görüntüye erişmek için kullanılan URL: https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/crop,g_se,x_100,y_200,w_900,h_900

Akıllı kırpma kullanarak bir görüntüyü kırpma

Bir görüntüyü akıllı kırpma kullanarak kırpmak için aşağıdaki parametreleri yapılandırın:

  • Eylemi belirtin: crop.

  • Algoritmayı belirtin: g_auto

  • (İsteğe bağlı) En boy oranını belirtin: ratio_width_height. Örneğin, ratio_1_1 1:1 kare kırpar ve ratio_16_9 16:9 geniş ekran kırpar. Belirtilmezse algoritma kırpma alanını otomatik olarak belirler.

Görüntüleri OSS SDK'larıyla işlemeden önce hedef paketin bir Intelligent Media Management (IMM) projesiyle ilişkilendirildiğinden emin olun.

Örnek kod

Java

OSS SDK for Java 3.17.4 veya sonraki bir sürüm gerekir.

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. 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 of 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 image. 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 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. 
        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 {
            // Perform smart cropping. 
            String image = "image/crop,g_auto";
            GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
            request.setProcess(image);
            // Save the processed image 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

OSS SDK for PHP 2.7.0 veya sonraki bir sürüm gerekir.

<?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. 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 source image. Do not include the bucket name in the full path. 
$object = "src.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);

// Perform smart cropping. 
$image = "image/crop,g_auto";

$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

OSS SDK for Python 2.18.4 veya sonraki bir sürüm gerekir.

# -*- 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. 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 ID of the Alibaba Cloud region in which the bucket is located. 
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the source image is stored in the root directory of the bucket, you can specify only the image name. Example: source-example.jpg. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/source-example.jpg. 
key = 'source-example.jpg'

# Specify the full path of the processed image. Example: D:\\target-example.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. 
local_file_name = 'D:\\target-example.jpg'

# Perform smart cropping. 
process = 'image/crop,g_auto'

# Use the get_object method and pass the processing instruction by using the process parameter. 
result = bucket.get_object_to_file(key, local_file_name, process=process)

Go

OSS SDK for Go 3.0.2 veya sonraki bir sürüm gerekir.

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. 
	// 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 your 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 source image. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/example.jpg. 
	sourceImageName := "example.jpg"
	// Specify the name of the processed image. 
	targetImageName := "D://dest.jpg"
	// Perform smart cropping. 
	image := "image/crop,g_auto"
	err = bucket.GetObjectToFile(sourceImageName, targetImageName, oss.Process(image))
	if err != nil {
		HandleError(err)
	}
}

Örnek efekt

Aşağıdaki tabloda, image/crop,g_auto parametresi ve akıllı algoritmalar uygulanarak görüntünün kırpılmasının etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

source image

image

Aşağıdaki örnekte, image/crop,g_auto,ratio_1_1 parametresi uygulanarak görüntünün 1:1 en boy oranıyla kırpılmasının etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

source image

image

Görüntüde algılanan en büyük yüze odaklanarak sabit boyutlu kırpma gerçekleştirme

Görüntüde algılanan en büyük yüze odaklanarak 200 × 200 piksellik bir alanı kırpın:

  • Eylemi belirtin: crop.

  • Görüntüde algılanan en büyük yüze odaklanarak bir alanı kırpın: g_face.

  • 200 × 200 piksellik bir alanı kırpın: w_200,h_200.

Görüntüleri OSS SDK'larıyla işlemeden önce hedef paketin bir IMM projesiyle ilişkilendirildiğinden emin olun.

Örnek kod

Java

OSS SDK for Java 3.17.4 veya sonraki bir sürüm gerekir.

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. 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 of 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 image. 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 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. 
        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 an area of 200 × 200 pixels from the center of the maximum face in the image. 
            String image = "image/crop,g_face,w_200,h_200";
            GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
            request.setProcess(image);
            // Save the processed image 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

OSS SDK for PHP 2.7.0 veya sonraki bir sürüm gerekir.

<?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. 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 source image. Do not include the bucket name in the full path. 
$object = "src.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);

// Crop an area of 200 × 200 pixels from the center of the maximum face in the image. 
$image = "image/crop,g_face,w_200,h_200";

$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

OSS SDK for Python 2.18.4 veya sonraki bir sürüm gerekir.

# -*- 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. 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 ID of the Alibaba Cloud region in which the bucket is located. 
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the source image is stored in the root directory of the bucket, you can specify only the image name. Example: source-example.jpg. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/source-example.jpg. 
key = 'source-example.jpg'

# Specify the full path of the processed image. Example: D:\\target-example.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. 
local_file_name = 'D:\\target-example.jpg'

# Crop an area of 200 × 200 pixels from the center of the maximum face in the image.
process = 'image/crop,g_face,w_200,h_200'

# Use the get_object method and pass the processing instruction by using the process parameter. 
result = bucket.get_object_to_file(key, local_file_name, process=process)

Go

OSS SDK for Go 3.0.2 veya sonraki bir sürüm gerekir.

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. 
	// 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 your 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 source image. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/example.jpg. 
	sourceImageName := "example.jpg"
	// Specify the name of the processed image. 
	targetImageName := "D://dest.jpg"
	// Crop an area of 200 × 200 pixels from the center of the maximum face in the image. 
	image := "image/crop,g_face,w_200,h_200"
	err = bucket.GetObjectToFile(sourceImageName, targetImageName, oss.Process(image))
	if err != nil {
		HandleError(err)
	}
}

Örnek efekt

Aşağıdaki örnekte, image/crop,g_face,w_200,h_200 kullanılarak görüntüde algılanan en büyük yüze odaklanarak 200 × 200 piksellik bir alanın kırpılmasının etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

source image

image

Görüntüde algılanan en büyük yüze odaklanarak bir alanı kırpma ve iki kat büyütme

Görüntüde algılanan en büyük yüz çevresinde bir kırpma alanı tanımlayın, ardından son kırpma işleminden önce bu alanı iki kat büyütün:

  • Eylemi belirtin: crop.

  • Görüntüde algılanan en büyük yüze odaklanarak bir alanı kırpın: g_face.

  • Kırpılan alanı algılanan en büyük yüzün iki katı boyutuna ölçeklendirin: p_200.

Görüntüleri OSS SDK'larıyla işlemeden önce hedef paketin bir IMM projesiyle ilişkilendirildiğinden emin olun.

Örnek kod

Java

OSS SDK for Java 3.17.4 veya sonraki bir sürüm gerekir.

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. 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 of 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 image. 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 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. 
        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 {
            // Scale the crop centered on the largest detected face to twice the size.
            String image = "image/crop,g_face,p_200";
            GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
            request.setProcess(image);
            // Save the processed image 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

OSS SDK for PHP 2.7.0 veya sonraki bir sürüm gerekir.

<?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. 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 source image. Do not include the bucket name in the full path. 
$object = "src.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);

// Scale the crop centered on the largest detected face to twice the size.
$image = "image/crop,g_face,p_200";

$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

OSS SDK for Python 2.18.4 veya sonraki bir sürüm gerekir.

# -*- 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. 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 ID of the Alibaba Cloud region in which the bucket is located. 
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# If the source image is stored in the root directory of the bucket, you can specify only the image name. Example: source-example.jpg. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/source-example.jpg. 
key = 'source-example.jpg'

# Specify the full path of the processed image. Example: D:\\target-example.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. 
local_file_name = 'D:\\target-example.jpg'

# Scale the crop centered on the largest detected face to twice the size.
process = 'image/crop,g_face,p_200'

# Use the get_object method and pass the processing instruction by using the process parameter.
result = bucket.get_object_to_file(key, local_file_name, process=process)

Go

OSS SDK for Go 3.0.2 veya sonraki bir sürüm gerekir.

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. 
	// 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 your 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 source image. If the source image is not stored in the root directory of the bucket, you must specify the full path of the source image. Example: exampledir/example.jpg. 
	sourceImageName := "example.jpg"
	// Specify the name of the processed image. 
	targetImageName := "D://dest.jpg"
	// Scale the crop centered on the largest detected face to twice the size.
	image := "image/crop,g_face,p_200"
	err = bucket.GetObjectToFile(sourceImageName, targetImageName, oss.Process(image))
	if err != nil {
		HandleError(err)
	}
}

Örnek efekt

Aşağıdaki örnekte, image/crop,g_face,p_200 parametresi kullanılarak görüntüde algılanan en büyük yüze odaklanarak bir alanın kırpılmasının ve iki kat büyütülmesinin etkisi gösterilmektedir:


Kaynak görüntü


İşlenen görüntü

source image

image