How to merge multiple PNG files together in Node.JS
2 min readApr 1, 2020
Merging PNG files with Node.JS is actually a lot more annoying than it might seem. For that reason, we will be avoiding the conventional method in favor of something a little easier: an API.
We will use npm install to add our client via this command:
npm install cloudmersive-convert-api-client --save
Next on the agenda, calling out PNG merging function with this code snippet:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.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 CloudmersiveConvertApiClient.MergeDocumentApi();var inputFile1 = "/path/to/file"; // File | First input file to perform the operation on.var inputFile2 = "/path/to/file"; // 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);
To finish, simply input your PNG files in their desired vertical order. It’s really as easy as that! We have a variety of related API functions that you might find useful, including image and document format conversion, as well as image editing and facial recognition.