How to Get Image Information in Python

Cloudmersive
2 min readJan 24, 2023

--

Image files typically store a huge amount of useful information about the content they’re displaying, and that information is often critically important to organizing, sharing, and editing that content at scale. The free-to-use API provided below can be used to quickly retrieve a wealth of information about any image file in your Python workflow (see below example JSON response model for a full list of retrieved information).


"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"
}
]
}

To take advantage of this API, use the below command to install the SDK:

pip install cloudmersive-convert-api-client

Next, add the imports and call the function:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'



# create an instance of the API class
api_instance = cloudmersive_convert_api_client.ConvertImageApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.

try:
# Get information about an image
api_response = api_instance.convert_image_get_image_info(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertImageApi->convert_image_get_image_info: %s\n" % e)

In order to complete your API call, you’ll just need to include a free-tier API key in the configuration.api_key field; you can get one by registering a free account on our website.

With your free-tier API key in hand, you’ll be able to call this API (or any of our free APIs) up to 800 times per month with zero additional commitments once you reach that limit.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet