DEV Community

Shahzad Ashraf
Shahzad Ashraf

Posted on

Simplied PNG File Merging in Node.js

Merging PNG files in Node.js no longer requires complex image processing libraries or manual handling. With the GroupDocs.Merger Cloud Node.js SDK, you can integrate robust image merging features into your applications in just a few steps. This cloud-powered SDK provides a clean and scalable solution for developers who want to focus on building features instead of wrestling with file management.

The setup is fast and straightforward. Install the SDK, configure your cloud credentials, and start merging multiple PNG images with simple REST API calls. By moving away from manual image-handling routines, you’ll free up valuable development time and gain the confidence that your application is built on a secure, reliable, and high-performance cloud service.

Now is the time to upgrade your workflow. Don’t let repetitive file operations slow down your projects. Add the GroupDocs.Merger Cloud Node.js SDK to your toolkit today and empower your Node.js applications with professional-grade file merging. Take action, streamline your processes, and start building smarter solutions that your users will appreciate.

For more information, please follow this link and check out our detailed article.

Working code example:

// Step 1: Import the GroupDocs.Merger Cloud module
const file_merger = require("groupdocs-merger-cloud");

// Step 2: Define your API credentials
const MyAppKey = "your-app-key";
const MyAppSid = "your-app-sid";

// Step 3: Initialize the DocumentApi with API credentials
const mergerApi = file_merger.DocumentApi.fromKeys(MyAppKey, MyAppSid);

// Step 4: Merge two PNG Files
(async () => {
    try {

        // Configure the PNG files to merge from cloud storage
        const file1 = new file_merger.JoinItem();
        file1.fileInfo = new file_merger.FileInfo();
        file1.fileInfo.filePath = "SampleFiles/source1.png";

        const file2 = new file_merger.JoinItem();
        file2.fileInfo = new file_merger.FileInfo();
        file2.fileInfo.filePath = "SampleFiles/source2.png";
        file2.imageJoinMode = file_merger.JoinItem.ImageJoinModeEnum.Horizontal;

        // Set up PNG merging options
        const options = new file_merger.JoinOptions();
        options.joinItems = [file1, file2];
        options.outputPath = "merger/merged.png";

        // Create a PNG file joining request
        const request = new file_merger.JoinRequest(options);

        // Execute the PNG file merger
        const response = await mergerApi.join(request);

    } catch (error) {
        console.error("Error during document merger:", error.message);
    }
})();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)