How to add a Gaussian blur to an image in Node.JS

Gaussian blur is a classic photo effect, and one that should be part of any proper repertoire. I’m going to show how to add it to yours using Node.JS.

To install our client, we simply add this snippet to our package.json.

"dependencies": {
"cloudmersive-image-api-client": "^1.2.3"

Now call our function and customize your blur parameters:

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 gaussian blur operationvar 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.filterGaussianBlur(radius, sigma, imageFile, callback);

Already done! Pretty easy, huh? For more quick and easy photo effects like this, check out what else this API can do, including posterization, cropping, drop shadows, and a whole lot more.

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