How to Merge PNG Files in Node.js

Cloudmersive
2 min readDec 30, 2022

--

The flexibility of Node.js makes it a great language for quickly integrating external web services. If you’re asking your application to merge PNG images into consolidated, singular files, the below API solution will save you a bunch of time. All you need to do is copy and paste ready-to-run code examples to structure your API call, and after that, supply a free-tier Cloudmersive API key (which you can get by registering a free account on our website).

First things first, to install the Node.js SDK, you’ll need to run the following command:

npm install cloudmersive-convert-api-client --save

Or, alternatively, add this snippet to your package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

With installation complete, all you need to do is call the function, supplying your apikey in the var Apikey parameter:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.MergeDocumentApi();

var inputFile1 = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | First input file to perform the operation on.

var inputFile2 = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Second input file to perform the operation on (more than 2 can be supplied).


var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.mergeDocumentPng(inputFile1, inputFile2, callback);

Nice and easy — you’re all done!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet