Convert Input Image to GIF Format in Python

In the last decade, GIFs have evolved to occupy a peculiar space between image & video, and have become firmly lodged in the way we express our (usually humorous) feelings towards a given subject. You can create a gif easily using the Cloudmersive Image API — specifically, the /image/convert/to/gif iteration will convert an input image into GIF format, and it’ll support dozens of input file formats from the get-go. Below, we’ll walk through how you can connect to this API in Python in a few easy steps.\

You can begin connecting by first using the below command for Python SDK installation:

pip install cloudmersive-image-api-client

Next, start off the callback function with the below code:

from __future__ import print_function
import time
import cloudmersive_image_api_client
from import ApiException
from pprint import pprint

At this point, you’ll need to authenticate your Cloudmersive API key. Copy this snippet into your code & input your key:

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

Finally, you can complete the API callback function with the remaining code below:

# create an instance of the API class
api_instance = cloudmersive_image_api_client.ConvertApi(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.
# Convert input image to GIF format
api_response = api_instance.convert_to_gif(image_file)
except ApiException as e:
print("Exception when calling ConvertApi->convert_to_gif: %s\n" % e)



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



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