How to Merge multiple JPG files into one in Java

Merge Multiple JPG Files into One in Java using REST API.

Merging JPG images can be a time-consuming and challenging task, especially when you have multiple images to merge. Fortunately, GroupDocs.Merger Cloud SDK for Java can help you to accomplish this task quickly and easily. In this article, we will demonstrate how to merge multiple JPG files into one in Java using REST API. So, let’s get started!

The following topics shall be covered in this article:

Java REST API to Merge JPG Images and SDK Installation

GroupDocs.Merger Cloud SDK for Java is a powerful and versatile tool that helps Java developers to merge, extract, rotate, change the document orientation to portrait or landscape, and modify files in the cloud. It is a cloud-based document manipulation and cross-platform API that supports a wide variety of file formats, including Word, PDF, Excel, PowerPoint, HTML, and many more. The SDK is easy to use and can be integrated easily into a Java-based application.

You can either download the API’s JAR file or install it using Maven by adding the following repository and dependency into your project’s pom.xml file:

Maven Repository:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>

Maven Dependency:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-merger-cloud</artifactId>
    <version>23.2</version>
    <scope>compile</scope>
</dependency>

Next, you need to sign up for a free trial account or purchase a subscription plan on the GroupDocs website and get your API key. Once you have the Client Id and Client Secret, add below code snippet into your Java application:

How to Combine JPG Files into One in Java using REST API

Merging JPG images in Java using GroupDocs.Merger Cloud SDK is a straightforward process. Here’s how to do it:

  1. Upload the JPG images to the cloud
  2. Combine multiple JPG files into one in Java
  3. Download the merged JPG file

Upload the Files

Firstly, upload the JPG files to the cloud using the code example given below:

As a result, the uploaded JPG files will be available in the files section of your dashboard on the cloud.

Combine JPG into One File in Java

This section provides step-by-step instructions and an example code snippet for merging JPG images into one:

  • Firstly, import the required classes into your Java file.
  • Secondly, create an instance of the DocumentApi class.
  • Thirdly, create an instance of the FileInfo class.
  • Next, call the setFilePath() method and pass the input file path as a parameter.
  • Then, create an instance of the JoinItem class.
  • Now, call the setFileInfo() method and pass the fileInfo1 parameter.
  • Next, create a second instance of the FileInfo and JoinItem classes.
  • Provide the input file path and fileInfo2 parameters.
  • Then, set image join mode to VERTICAL or HORIZONTAL.
  • Add more JoinItems for merging more than two documents.
  • After that, create an instance of the JoinOptions() class.
  • Then, add a comma-separated list of created join items.
  • Next, set the output file path.
  • Now, create an instance of the JoinRequest() class and pass the JoinOptions in the parameter.
  • Finally, merge JPG files by calling the join() method of the DocumentApi and passing the JoinRequest parameter.

The following code snippet shows how to merge multiple JPG files into one file in Java using REST API:

You can see the output in the image below:

How to Combine multiple JPG images into one image in Java

Combine JPG into One File in Java.

Download the File

The above code sample will save the merged JPG file on the cloud. You can download it using the following code sample:

Free Online JPG Images Merger

How to merge JPG files online for free? Please try the free JPG Merger to combine multiple JPG files into one online. This online document merger is developed using the above-mentioned Groupdocs.Merger Cloud APIs.

Conclusion

In this article, we have explored how to merge JPG images into one in Java using GroupDocs.Merger Cloud SDK. The following is what you have learned from this article:

  • how to merge two JPG images into one in Java on the cloud;
  • programmatically upload and download the merged file in Java;
  • and merge JPG files for free using an online JPG file merger.

Additionally, we also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser. Java SDK’s complete source code is freely available on Github. Please check the GroupDocs.Merger Cloud SDK for Java Examples here.

Moreover, we suggest you follow our Getting Started guide for detailed steps and API usage.

Finally, we keep writing new blog posts on different document operations using REST API. So, please get in touch for the latest updates.

Ask a question

If you have any questions about the Images Merger API, please feel free to ask us on the Free Support Forum.

FAQs

Is the GroupDocs.Merger Cloud SDK free to use?

The GroupDocs.Merger Cloud SDK offers a free trial period, but there are subscription plans available if you want to continue using the SDK after the trial period.

How do I merge multiple JPG images into one in Java?

You can merge and combine JPG files into one in Java using GroupDocs.Merger Cloud SDK for Java.

What file formats does the GroupDocs.Merger Cloud SDK support?

The GroupDocs.Merger Cloud SDK supports a wide range of file formats, including JPG images, Word, PDF, DOCX, XLSX, HTML, and more.

Can I merge multiple JPG images into a single image using GroupDocs.Merger Cloud SDK for Java?

Yes, GroupDocs.Merger Cloud SDK for Java allows developers to merge multiple JPG images into a single image using its merge feature.

See Also

For further information on related topics, we suggest taking a look at the following articles: