How to Normalize Image Rotation & Remove EXIF Rotation Data using Python
Processing image files gets a lot easier when the files get smaller. Our Image Normalization API kills two birds with one stone, taking its cue from rotational data included within an image’s EXIF data to automatically re-orient the image correctly & then entirely remove that data from the file, reducing its burden on subsequent image processing or sharing operations. It’s easy to take advantage of this API with copy & paste code examples in Python. Below, we’ll walk through how to structure your API call & authenticate API access with a free Cloudmersive API key.
First things first — we need to install the Python SDK. We can do that by running the following command:
pip install cloudmersive-image-api-client
With installation complete, let’s now include the imports:
from __future__ import print_function
import time
import cloudmersive_image_api_client
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint
Lastly, let’s call the function, beginning by including the API key authorization snippet. To get an API key, simply visit our website and register a free account (this will provide a limit of 800 API calls per month).
# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'# create an instance of the API class
api_instance = cloudmersive_image_api_client.EditApi(cloudmersive_image_api_client.ApiClient(configuration))
image_file = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try:
# Normalizes image rotation and removes EXIF rotation data
api_response = api_instance.edit_auto_orient(image_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditApi->edit_auto_orient: %s\n" % e)