How to Remove Transparency from an Image using Node.js
One way to remove the transparency from an image file entails rendering the original image over a white background. Our Transparency Removal API does exactly that, retaining the same resolution and file format as the original input image. Below, we’ll demonstrate how to structure an API call using tbe ready-to-run code snippets provided in Node.js below.
Let’s begin by installing the SDK. Run the below command:
npm install cloudmersive-image-api-client --save
Now let’s include the code block below. Include your Cloudmersive API key (obtainable by registering a free account on our website) where indicated above the function:
var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');
var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';var apiInstance = new CloudmersiveImageApiClient.EditApi();var imageFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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.editRemoveTransparency(imageFile, callback);
That’s all you need — no more coding required.