Bazı görüntüler, görüntü nitelikleri ve çekim ayarlarını içeren Değiştirilebilir Görüntü Dosyası Biçimi (EXIF) verileri barındırabilir. Bir görüntünün EXIF verileri; sıkıştırma oranı, yön, yatay çözünürlük ve dikey çözünürlük gibi görüntü bilgilerini içerir. Bir görüntünün EXIF verilerini elde etmek istiyorsanız görüntünün URL'sine info parametresini ekleyin.
Parametreler
Eylem: info
Dönen bilgiler JSON biçimindedir. Yanıttaki her alan "FieldName": {"value": "field value"} yapısını kullanır ve tüm alan değerleri dizelerdir.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bir görüntü işleme isteğinde info eylemini diğer eylemlerle birlikte kullanamazsınız. Örneğin bir görüntüyü yeniden boyutlandırmak ve aynı anda yeniden boyutlandırılmış görüntü hakkında bilgi sorgulamak için image/resize,s_700,limit_0/info ifadesini kullanamazsınız.
Sınırlamalar
Info eylemini yalnızca JPG, PNG, BMP, GIF, WebP, TIFF ve HEIC görüntüleri hakkında bilgi sorgulamak için kullanabilirsiniz.
PNG biçimi desteklenmesine rağmen PNG görüntülerinin EXIF verilerini sorgulamak için info eylemini kullanamazsınız.
İşlemler
Görüntü işleme parametrelerini URL'ler, OSS SDK'ları veya RESTful API'ler kullanarak yapılandırabilirsiniz. URL'ler herkese açık erişilebilir görüntüler için uygundur. Özel görüntüler için OSS SDK'larını veya RESTful API'leri kullanmanızı öneririz. Ayrıntılar için bkz. Görüntü işleme yöntemleri.
Public-read veya public-read-write görüntüler hakkında bilgi alma
Görüntü işleme parametrelerini doğrudan URL'lere ekleyerek public-read veya public-read-write görüntüler hakkında bilgi alabilirsiniz.
-
EXIF verisi içermeyen bir görüntü hakkında bilgi sorgulama
https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/info
Info parametresini eklediğinizde
FileSize,Format,FrameCount,ImageHeightveImageWidthtemel görüntü bilgileri olduğundan desteklenen her görüntü için döndürülür.ResolutionUnit,XResolutionveYResolutionyalnızca görüntü çözünürlük meta verisi taşıyorsa döndürülür. Diğer tüm EXIF alanları yalnızca görüntü EXIF verisi içeriyorsa döndürülür. Aşağıdaki örnekteki görüntü EXIF verisi içermemektedir ancak çözünürlük meta verisi taşımaktadır. Bu nedenle yanıt temel bilgilere ek olarak çözünürlük alanlarını da içerir.{ "FileSize": {"value": "21839"}, "Format": {"value": "jpg"}, "FrameCount": {"value": "1"}, "ImageHeight": {"value": "267"}, "ImageWidth": {"value": "400"}, "ResolutionUnit": {"value": "1"}, "XResolution": {"value": "1/1"}, "YResolution": {"value": "1/1"} } -
EXIF verisi içeren bir görüntü hakkında bilgi sorgulama
https://image-demo.oss-cn-hangzhou.aliyuncs.com/f.jpg?x-oss-process=image/info
EXIF verisi içeren bir görüntünün URL'sine info parametresini eklerseniz yanıt görüntüyle ilgili temel bilgileri ve görüntünün EXIF verilerini içerir. Daha fazla bilgi için bkz. Exif Version 2.31.
{ "Compression": {"value": "6"}, "DateTime": {"value": "2015:02:11 15:38:27"}, "ExifTag": {"value": "2212"}, "FileSize": {"value": "23471"}, "Format": {"value": "jpg"}, "FrameCount": {"value": "1"}, "GPSLatitude": {"value": "0deg "}, "GPSLatitudeRef": {"value": "North"}, "GPSLongitude": {"value": "0deg "}, "GPSLongitudeRef": {"value": "East"}, "GPSMapDatum": {"value": "WGS-84"}, "GPSTag": {"value": "4292"}, "GPSVersionID": {"value": "2 2 0 0"}, "ImageHeight": {"value": "333"}, "ImageWidth": {"value": "424"}, "JPEGInterchangeFormat": {"value": "4518"}, "JPEGInterchangeFormatLength": {"value": "3232"}, "Orientation": {"value": "7"}, "ResolutionUnit": {"value": "2"}, "Software": {"value": "Microsoft Windows Photo Viewer 6.1.7600.16385"}, "XResolution": {"value": "96/1"}, "YResolution": {"value": "96/1"}}
Özel görüntüler hakkında bilgi alma
Alibaba Cloud SDK veya REST API kullanarak özel görüntüler hakkında bilgi alabilirsiniz.
Alibaba Cloud SDK kullanma
Aşağıdaki örnek kod yaygın programlama dilleri için SDK'ların görüntüler hakkında bilgi almak üzere nasıl kullanılacağına ilişkin örnekler sunar. Diğer programlama dilleri için SDK'ları kullanarak görüntüler hakkında bilgi alma konusunda daha fazla bilgi için bkz. SDK Başvurusu.
Java
Java SDK sürüm 3.17.4 veya üstü gereklidir.
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class Demo{
public static void main(String[] args) throws ClientException, ClientException {
// yourEndpoint Specify the endpoint of the region in which the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the endpoint of the region. For 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.
String bucketName = "examplebucket";
// Specify the name of the image if it is stored in the root directory of the bucket. If it is stored elsewhere, you must specify the full path of the image. Example: exampledir/example.jpg.
String key = "example.jpg";
// Create an OSSClient instance.
// Call the shutdown method to release resources when the OSSClient is no longer in use.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Create a request to obtain information about the image.
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
getObjectRequest.setProcess("image/info");
// Use getObject and input instructions via process parameters.
OSSObject ossObject = ossClient.getObject(getObjectRequest);
// Read and print information.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
String imageInfo = baos.toString("UTF-8");
System.out.println("Image Info:");
System.out.println(imageInfo);
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
} finally {
// Shut down OSSClient
ossClient.shutdown();
}
}
}
PHP
PHP SDK sürüm 2.7.0 veya üstü 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;
try {
// 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 name of the image if it is stored in the root directory of the bucket. If it is stored elsewhere, you must specify the full path of the image. Example: exampledir/example.jpg.
$key = 'example.jpg';
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
// Specify the Region ID.
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Create a request to obtain information about the image.
$options[$ossClient::OSS_PROCESS] = "image/info";
$result = $ossClient->getObject($bucket,$key,$options);
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
Go
Go SDK 3.0.2 veya üstü gereklidir.
package main
import (
"fmt"
"io"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
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.
// Specify the Region ID. Example: cn-hangzhou.
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the name of the bucket. Example: examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the name of the image if it is stored in the root directory of the bucket. If it is stored elsewhere, you must specify the full path of the image. Example: exampledir/example.jpg.
// Create a request to obtain information about the image by using oss.Process.
body, err := bucket.GetObject("example.jpg", oss.Process("image/info"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
defer body.Close()
data, err := io.ReadAll(body)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println("data:", string(data))
}
RESTful API kullanma
İşletmeniz yüksek düzeyde özelleştirme gerektiriyorsa doğrudan RESTful API'leri çağırabilirsiniz. Bir API'yi doğrudan çağırmak için imza hesaplamasını kodunuza dahil etmeniz gerekir. Daha fazla bilgi için bkz. (Önerilen) V4 imzası dahil etme.
Görüntüleri işlemek için GetObject isteklerine IMG parametreleri veya görüntü stili parametreleri ekleyebilirsiniz.
GET /oss.jpg?x-oss-process=image/info 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
SSS
Özel bir görüntü hakkında bilgiyi nasıl sorgularım?
Özel bir görüntü hakkında bilgi sorgulamak için OSS SDK'larını kullanarak imzalı bir URL'ye info parametresini ekleyin ve ardından görüntüye erişmek için bu URL'yi kullanın.
-
İmzalı bir URL oluşturun.
Aşağıdaki örnek kod imzalı bir URL oluşturmak için Java için OSS SDK'nın nasıl kullanılacağına ilişkin bir örnek sunar:
import com.aliyun.oss.*; import com.aliyun.oss.common.auth.*; import com.aliyun.oss.common.comm.SignVersion; import com.aliyun.oss.model.GeneratePresignedUrlRequest; import java.net.URL; import java.util.Date; 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"; // For security purposes, we recommend that you do not save access credentials in the project code. In this example, access credentials are obtained from environment variables. Before you run the sample code, make sure that the 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 = "exampleobject.jpg"; // Create an OSSClient instance. // Call the shutdown method to release resources when the OSSClient is no longer in use. ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration(); // Explicitly declare the use of the V4 signature algorithm. clientBuilderConfiguration.setSignatureVersion(SignVersion.V4); OSS ossClient = OSSClientBuilder.create() .endpoint(endpoint) .credentialsProvider(credentialsProvider) .clientConfiguration(clientBuilderConfiguration) .region(region) .build(); try { // Query information about the image object. String style = "image/info"; // Set the validity period of the signed URL to 10 minutes. Date expiration = new Date(new Date().getTime() + 1000 * 60 * 10 ); GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET); req.setExpiration(expiration); req.setProcess(style); URL signedUrl = ossClient.generatePresignedUrl(req); System.out.println(signedUrl); } 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(); } } } } Görüntü bilgilerini sorgulamak için tarayıcıdan görüntüye erişmek amacıyla imzalı URL'yi kullanın.