GroupDocs.Merger allows developers to combine multiple JPG documents in the preferred order and save them as a single file.
About JPG File Format
JPEG is a type of image format that is saved using the method of lossy compression. The output image, as result of compression, is a trade-off between storage size and image quality. Users can adjust the compression level to achieve the desired quality level while at the same time reduce the storage size. Image quality is negligibly affected if 10:1 compression is applied to the image. The higher the compression value, the higher the degradation in image quality.
Download and Configure
You can follow the steps below to reference GroupDocs.Merger for Java downloaded from official website Downloads section:
Unpack zip archive .
Switch to lib folder.
Run install.bat (for Windows) or install.sh (for Linux) file to install the library in your local maven repository.
After this you should add the merger dependency block to your pom.xml project file.
Source JPG images
How to merge JPG files as photo collage
The following example demonstrates how to merge image files as photo collage with several lines of Java code:
Create an instance of Merger class and pass source image file path as a constructor parameter. You may specify absolute or relative file path as per your requirements.
Add another image file to merge with join method and pass instance of ImageJoinOptions class as a method parameter. Repeat this step for other image documents you want to merge.
Call Merger class save method and specify the filename for the merged image file as parameter.
// Load the source image file
Mergermerger=newMerger("c:\sample1.jpg")// Define image join options with horizontal join mode
ImageJoinOptionsjoinOptions=newImageJoinOptions(ImageJoinMode.Horizontal);// Add another image file to merge
merger.join("c:\sample2.jpg",joinOptions);// Define image join options with vertical join mode
joinOptions=newImageJoinOptions(ImageJoinMode.Vertical);// Add next image file to merge
merger.join("c:\sample3.jpg",joinOptions);// Merge image files and save result
merger.save("c:\merged.jpg");