How to add motion blur to an image in Node.JS

Adding a touch of motion blur to a photo can really bring out the energy for your audience. While easy to perform in a photo editing program on one image, this can quickly become very inconvenient when working with any amount of volume whatsoever. You need an automated approach, and we are here today to give you just that and in record time, too.

Let’s kick things off by running this command, which will have npm install set up our API client so we can continue.

npm install cloudmersive-image-api-client --save

Next call filterMotionBlur.

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveImageApiClient.FilterApi();var radius = 56; // Number | Radius in pixels of the blur operation; a larger radius will produce a greater blur effectvar sigma = 56; // Number | Sigma, or variance, of the motion blur operationvar angle = 56; // Number | Angle of the motion blur in degreesvar imageFile = "/path/to/file"; // File | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.filterMotionBlur(radius, sigma, angle, imageFile, callback);

You can customize the parameters of the motion blur effect, then input your imageFile and let the API return your blurred image. Easy as pie!

Image for post

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