How to add a Gaussian blur to an image in Node.JS
2 min readApr 5, 2020
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.