Combine PNG Files in Java -  Online Images Merger

GroupDocs.Merger Cloud SDK for Java lets you programmatically combine PNG files into one large file without overlapping. You will definitely find these Cloud SDKs and REST APIs beneficial if you want to build a PNG merger for your software. In addition, GroupDocs.Merger also lets you configure the request before making an API call to join PNG files. So, let’s start this guide and explore how to combine PNG files in Java. We will cover the installation steps and the code snippet to merge PNG files programmatically. So, go through this blog post thoroughly and do not miss any section.

The following sections will be covered:

PNG Merger - API Installation

The installation of this library takes only a few seconds if you have installed Java on your local machine. Thus, you can install it in two ways. First, download the JAR file or install it using the following Maven configurations to install this image merger library:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>
<dependency>
    <groupId>com.groupdocs</groupId
    <artifactId>groupdocs-merger-cloud</artifactId>
    <version>23.4</version>
    <scope>compile</scope>
</dependency>

The next step is to set up an application and obtain the API credentials (Client ID + Client Secret) from the API Cloud dashboard, you can visit this guide on how to obtain API credentials in case you find any difficulty.

Combine PNG Files in Java

So far, we have completed the installation and have obtained our Client ID and Client Secret. Further, we have two source PNG files on the API cloud dashboard. You can follow this guide to learn how to programmatically upload files to the dashboard.

Note: You can upload files to the API Cloud dashboard manually too.

Please follow the following steps to merge PNG files in Java:

  • Initialize an object of the Configuration class with Client ID and Client Secret.
  • Instantiate an instance of the DocumentApi class with the object of the Configuration class.
  • Create an object of the FileInfo class.
  • Invoke the setFilePath method to define the PNG image path.
  • Instantiate an instance of the JoinItem class.
  • Call the setFileInfo method of the JoinItem class to define the information of the first image file.
  • Set the orientation of the merged file by calling the setImageJoinMode method.
  • Create an object of the JoinOptions class.
  • Invoke the setJoinItems method to define both images.
  • Call the setOutputPath function to set the output path for the merged PNG files.
  • Initialize an object of the JoinRequest class with an object of the JoinOptions class.
  • Call the join method to combine PNG files into one.
  • You can copy & paste the following code sample to build a file format converter:

The following code sample demonstrates how to join PNG files in Java:

The above code snippet will generate a merged file in the “test” folder in the API Cloud dashboard. Again, you can download the merged image manually or programmatically by invoking the DownloadFile method. You can see the output in the image below:

join png files

Online Image Merger

There is an online PNG merger powered by GroupDocs.Merger. This online tool is web-based and offers robust image-merging capabilities. In addition, you can combine PNG files into one by just dragging and dropping the files into the user interface. It does all the imaging with just one click. Above all, it is free to use and there is no need to avail of any subscription to use this online image merger.

online images merger

Final Thoughts

We are ending this article here. We hope you have learned how to combine PNG files in Java. This PNG merger library offers many other features to customize the PNG images that you can find in the documentation. In addition, please visit our live APIs here. Further, we suggest you follow our Getting Started Guide in order to start development. Finally, groupdocs.cloud is writing new articles. So, please stay in touch for the latest updates.

Help is Available

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

Frequently Asked Questions – FAQs

How to combine 2 PNG files into one?

You can join PNG files using GroupDocs.Merger Cloud SDK for Java. Please visit this link for further details.

How to combine multiple files into one file in Java?

This online image merger lets you merge PNG files quickly. For a programmatic solution, please visit this Getting Started Guide

See Also