Get Image Properties Introduction
With Aspose.Imaging REST APIs you can get properties of an image. Image properties can be obtained using one of the following two APIs:
The first API expects you to first upload an image to Cloud Storage then pass its name in the API URL. Whereas, with the second API, you can simply pass the image in the request body.
Resource URI
Aspose.Imaging Cloud APIs Swagger UI lets you call this REST API directly from the browser. The description of the API and its parameters are also given there.
cURL Example
Request
Copy
curl - v "https://api.aspose.cloud/connect/token" \
- X POST \
- d ' grant_type = client_credentials & client_id = xxxx & client_secret = xxxx ' \
- H "Content-Type: application/x-www-form-urlencoded" \
- H "Accept: application/json"
curl - v "https://api.aspose.cloud/v3/imaging/WaterMark.bmp/properties" \
- X GET \
- H "Content-Type: application/json" \
- H "Accept: application/json" \
- H "Authorization: Bearer <jwt token>"
Response
Copy
{
"Height" : 500 ,
"Width" : 500 ,
"BitsPerPixel" : 24 ,
"BmpProperties" : {
"Compression" : "Rgb"
},
"GifProperties" : null ,
"JpegProperties" : null ,
"PngProperties" : null ,
"TiffProperties" : null ,
"PsdProperties" : null ,
"DjvuProperties" : null ,
"WebPProperties" : null ,
"Jpeg2000Properties" : null ,
"DicomProperties" : null ,
"DngProperties" : null ,
"OdgProperties" : null ,
"HorizontalResolution" : 96 . 012 ,
"VerticalResolution" : 96 . 012 ,
"IsCached" : false ,
"Code" : 200 ,
"Status" : "OK"
}
SDKs
Using an SDK (API client) is the quickest way for a developer to speed up the development. An SDK takes care of a lot of low-level details of making requests and handling responses and lets you focus on writing code specific to your particular project. Check out our GitHub repository for a complete list of Aspose.Imaging Cloud SDKs along with working examples, to get you started in no time. Please check Available SDKs article to learn how to add an SDK to your project.
SDK Examples
.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-imaging-cloud/aspose-imaging-cloud-dotnet
public void GetImagePropertiesFromStorage()
{
string fileName = "Sample.tiff";
// Upload local image to Cloud Storage
using (FileStream localInputImage = File.OpenRead(ImagingBase.PathToDataFiles + fileName))
{
var uploadFileRequest = new UploadFileRequest(fileName, localInputImage);
FilesUploadResult result = this.ImagingApi.UploadFile(uploadFileRequest);
}
// Get properties of an image
// Folder with image to process. The value is null because the file is saved at the root of the storage
string folder = null;
string storage = null; // We are using default Cloud Storage
GetImagePropertiesRequest getImagePropertiesRequest = new GetImagePropertiesRequest(fileName, folder,
storage);
ImagingResponse imagingResponse = this.ImagingApi.GetImageProperties(getImagePropertiesRequest);
}
Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String APP_KEY = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String APP_SID = ""; // Get AppKey and AppSID from https:dashboard.aspose.cloud/
String DATA_PATH = "src/main/resources/";
ImagingApi imagingApi = new ImagingApi(APP_KEY, APP_SID);
String fileName = "Sample.tiff";
try {
// Upload local image to Cloud Storage
File inputFile = new File(Main.DATA_PATH + fileName);
FileInputStream localInputImageStream = new FileInputStream(inputFile);
byte[] localInputImage = IOUtils.toByteArray(localInputImageStream);
UploadFileRequest uploadFileRequest = new UploadFileRequest(fileName, localInputImage, null);
FilesUploadResult result = imagingApi.uploadFile(uploadFileRequest);
// Get properties of an image
// Folder with image to process. The value is null because the file is saved at the root of the storage
String folder = null;
String storage = null; // We are using default Cloud Storage
GetImagePropertiesRequest getImagePropertiesRequest = new GetImagePropertiesRequest(fileName, folder,
storage);
ImagingResponse imagingResponse = imagingApi.getImageProperties(getImagePropertiesRequest);
System.out.println(imagingResponse);
} catch (Exception e) {
System.out.println(e.getMessage());
}