How to add motion blur to an image in Python

Motion blur: a great way to add visual interest to any image and an excellent addition to any photo editing toolkit. So what’s a good way to set this up that’s not going to waste an entire day? Well, how about an API?

Our API will need its client installed before we can do much else. Use pip installer, like so:

pip install cloudmersive-image-api-client

Continuing on, we shall write out our function call with this block of code:

from __future__ import print_functionimport timeimport cloudmersive_image_api_clientfrom cloudmersive_image_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_image_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_image_api_client.FilterApi(cloudmersive_image_api_client.ApiClient(configuration))radius = 56 # int | Radius in pixels of the blur operation; a larger radius will produce a greater blur effectsigma = 56 # int | Sigma, or variance, of the motion blur operationangle = 56 # int | Angle of the motion blur in degreesimage_file = '/path/to/file' # file | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.try:# Perform a motion blur on the input imageapi_response = api_instance.filter_motion_blur(radius, sigma, angle, image_file)pprint(api_response)except ApiException as e:print("Exception when calling FilterApi->filter_motion_blur: %s\n" % e)

We need to enter the parameters radius, sigma, and angle for our blur, as well as our target image. Now we just wait for the API to do its thing and return our nice blurred image. Just think about how much time you just saved!

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