How to get image information in Java

Today we are going to show you how to retrieve image information with Java in just a few short minutes. Let’s get started.

First order of business, installing our library. Since we will employ Jitpack for this purpose, we simply need to add some references to Maven POM.

Repositories reference.

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Dependencies reference.

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.34</version>
</dependency>
</dependencies>

Moving on, we now need to call our convertImageGetImageInfo function and provide an inputFile.

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.ConvertImageApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");ConvertImageApi apiInstance = new ConvertImageApi();File inputFile = new File("/path/to/file"); // File | Input file to perform the operation on.try {GetImageInfoResult result = apiInstance.convertImageGetImageInfo(inputFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling ConvertImageApi#convertImageGetImageInfo");e.printStackTrace();}

And that’s all there was to it. Here is how your return will be presented, which will also show you what kind of information you shall receive.

{
"Successful": true,
"ColorSpace": "string",
"ColorType": "string",
"Width": 0,
"Height": 0,
"CompressionLevel": 0,
"ImageHashSignature": "string",
"HasTransparency": true,
"MimeType": "string",
"ImageFormat": "string",
"DPIUnit": "string",
"DPI": 0,
"ColorCount": 0,
"BitDepth": 0,
"Comment": "string",
"ExifProfileName": "string",
"ExifValues": [
{
"Tag": "string",
"DataType": "string",
"DataValue": "string"
}
]
}
Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store