Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Image styles (Python SDK V1)

Son Güncelleme:Oct 01, 2026

Object Storage Service (OSS) içinde bir görüntü stili; ölçeklendirme, kırpma, döndürme ve filigran ekleme gibi bir dizi görüntü işleme işlemini gerçekleştirmenize olanak tanır. Bu işlemleri tanımlamak için bir görüntü stili oluşturabilir ve ardından hızlı işleme ile dönüştürme amacıyla bu stili paketinizdeki görüntülere uygulayabilirsiniz.

Notlar

  • Görüntü stillerinin desteklediği görüntü işleme parametreleri hakkında daha fazla bilgi için bkz. Görüntü işleme.

  • Bu konuda Çin (Hangzhou) bölgesinin genel uç noktası kullanılmıştır. OSS ile aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'e erişmek istiyorsanız dahili bir uç nokta kullanın. OSS bölgeleri ve uç noktaları hakkında daha fazla bilgi için bkz. Bölgeler ve uç noktalar.

  • Bu konuda erişim kimlik bilgileri ortam değişkenlerinden alınır. Erişim kimlik bilgilerinin nasıl yapılandırılacağı hakkında daha fazla bilgi için bkz. OSS SDK for Python 1.0 kullanarak erişim kimlik bilgilerini yapılandırma.

  • Bu konu, bir OSS uç noktasıyla bir OSSClient örneğinin nasıl oluşturulacağını göstermektedir. Özel etki alanı kullanımı veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. Başlatma.

  • İzinler

    Bir Alibaba Cloud hesabı varsayılan olarak görüntü stili işlemleri için gerekli izinlere sahiptir. Bu işlemleri bir Resource Access Management (RAM) kullanıcısı olarak veya STS kullanarak gerçekleştirmek için ilgili izinlere sahip olmanız gerekir:

    • Bir görüntü stili oluşturmak için oss:PutStyle iznine sahip olmanız gerekir.

    • Bir paketteki belirli bir görüntü stili hakkında bilgi sorgulamak için oss:GetStyle iznine sahip olmanız gerekir.

    • Bir pakette oluşturulan tüm görüntü stillerini sorgulamak için oss:ListStyle iznine sahip olmanız gerekir.

    • Bir paketteki belirli bir görüntü stilini silmek için oss:DeleteStyle iznine sahip olmanız gerekir.

    Daha fazla bilgi için bkz. RAM kullanıcısına özel erişim ilkeleri atama.

Görüntü stili oluşturma

Bir paket için en fazla 50 görüntü stili oluşturabilirsiniz. Aşağıdaki kod, bir görüntü stilinin nasıl oluşturulacağını gösterir:

# -*- 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 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 = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the region of the endpoint. Example: cn-hangzhou. This parameter is required if you use the V4 signature algorithm.
region = "cn-hangzhou"

# Replace examplebucket with the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Specify the name of the image style, such as imagestyle.
style = 'imagestyle'
# Specify the operation of the image style, such as resizing the image to a width of 200 pixels.
content = 'image/resize,w_200'

# Create an image style.
result = bucket.put_bucket_style(style, content)
print('The style is created. The status code is: ' + str(result.status))

Bir görüntü stili oluşturduktan sonra bu stili görüntüleri işlemek için kullanabilirsiniz. Daha fazla bilgi için bkz. Görüntüleri işlemek için görüntü stillerini kullanma.

Belirtilen bir görüntü stilini sorgulama

Aşağıdaki kod, bir paketteki belirtilen bir görüntü stili hakkında bilgi sorgulamayı gösterir.

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

# Obtain access credentials from environment variables. Before you run this code, set the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Set endpoint to the endpoint of the region where the bucket is located. For example, for the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Set region to the region that corresponds to your endpoint, such as cn-hangzhou. Note: This parameter is required for V4 signatures.
region = "cn-hangzhou"

# Replace examplebucket with your bucket name.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Specify the name of the image style, such as imagestyle.
style = 'imagestyle'

# Query information about the specified image style in the examplebucket bucket.
result = bucket.get_bucket_style(style)
print('name: ' + result.name)
print('content: ' + result.content)

Tüm görüntü stillerini sorgulama

Aşağıdaki kod, bir pakette oluşturulan tüm görüntü stillerini sorgulamayı gösterir.

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

# Obtain access credentials from environment variables. Before running this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify 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 = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the region that corresponds to the endpoint, such as cn-hangzhou. Note: This parameter is required for V4 signatures.
region = "cn-hangzhou"

# Replace examplebucket with your bucket name.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Query all created image styles in the examplebucket bucket.
result = bucket.list_bucket_style()
for sty in result.styles:
    print('name: ' + sty.name)
    print('content: ' + sty.content)

Belirtilen bir görüntü stilini silme

Belirtilen bir görüntü stilini examplebucket paketinden silmek için aşağıdaki kodu kullanın.

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

# Obtain access credentials from environment variables. Before you run this code, set the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Set endpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Set the region that corresponds to the endpoint, such as cn-hangzhou. This parameter is required for V4 signatures.
region = "cn-hangzhou"

# Replace examplebucket with your bucket name.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Specify the name of the image style, such as imagestyle.
style = 'imagestyle'

# Delete the specified image style.
result = bucket.delete_bucket_style(style)
print('Style deleted successfully. Return status: ' + str(result.status))

İlgili konular

  • Bir görüntü stili oluşturmaya yönelik API işlemi hakkında daha fazla bilgi için bkz. PutStyle.

  • Bir paketteki belirli bir görüntü stilini sorgulamaya yönelik API işlemi hakkında daha fazla bilgi için bkz. GetStyle.

  • Bir paketteki tüm görüntü stillerini listelemeye yönelik API işlemi hakkında daha fazla bilgi için bkz. ListStyle.

  • Bir paketteki belirli bir görüntü stilini silmeye yönelik API işlemi hakkında daha fazla bilgi için bkz. DeleteStyle.