Merge PNG Files in Node.js

This blog post introduces GroupDocs.Merger which has exposed Cloud SDks and REST APIs to merge various file formats programmatically. In addition, there is a web-based online tool to perform file merging and it is also powered by GroupDocs.Merger Cloud SDK. However, in this blog post, we will learn how to merge PNG files in Node.js and also we will go through this online tool to combine PNG files into one. Therefore, please read this article thoroughly, and by the end of this tutorial, you will be able to merge PNG images programmatically.

We will cover the following sections in this article:

PNG Merger Library Installation

Let’s install GroupDocs.Merger Cloud SDK for Node.js in our project. This enterprise-level PNG merger library is easy to install and offers a wide range of features to merge PNG files programmatically. So, you may run the following command into the terminal/CMD :

npm install groupdocs-merger-cloud

Upon a successful installation, the next step is to obtain the API credentials (Client ID + Client Secret). There is a very simple process of getting API credentials from the API Cloud dashboard.

Please visit this guide in case you face any difficulty in obtaining API credentials.

Merge PNG Files in Node.js Programmatically

Before jumping toward writing code, please be aware we have uploaded two source PNG images to the API Cloud dashboard. In fact, you may upload manually or programmatically by invoking this UploadFile method.

The following steps show how to combine PNG files in Node.js:

  • Include the groupdocs-merger-cloud module in your Node.js project.
  • Obtain API credentials from the API Cloud Dashboard.
  • Call the fromKeys method of the DocumentApi class and pass the API credentials.
  • Initialize an instance of the JoinItem class that describes the document for the join operation.
  • Instantiate an object of the FileInfo class.
  • Define the file path of the source PNG files by calling the filePath property.
  • Create an object of the JoinOptions class.
  • Call the JoinItems property to assign the source document array.
  • Set the output path for generated merged PNG images.
  • Initialize an instance of the JoinRequest class and pass it into the join method to merge JPG files.

The following code sample demonstrates how to merge PNG images programmatically:

Once you run the main file, you will see a new file(i.e. merged.png) generated in the “Output” folder in the API Cloud dashboard. The output of the above code snippet is shown below:

combine png files into one

Again, you may download the file manually or programmatically by invoking the DownloadFile method.

Merge PNG Files Online

So far, we have learned how to merge PNG files in Node.js programmatically. Now this guide will take you to the online version of this PNG merger library. So, it is quite easy to use and performs the tasks in a few seconds. Above all, it is free to use and requires no account creation or subscription.

merge png files online

Final Thoughts

To conclude, we have gone through how to merge PNG files in Node.js programmatically. In addition, we also covered the steps and the code sample that you can use to merge PNG images. Moreover, this blog post will help you if you want to build a PNG merger module in Node.js. Well, you may visit the documentation to learn about the other features exposed by GroupDocs.Merger Cloud SDK for Node.js. You may interact with the live API here and also you can visit the GitHub repo since it is open-source.

Further, we recommend you follow our Getting Started guide.

Finally, is writing new blog posts. So, please stay in touch for the regular updates.

Ask a question

You can let us know about your questions or queries on our forum.

Frequently Asked Questions – FAQs

How to merge two files in Node.js?

GroupDocs.Merger Cloud SDK for Node.js offers a huge stack of features to merge two files in one. Please visit the documentation to learn more.

How to merge multiple images into one?

Please visit this link to combine PNG files into one.

See Also