Merge images

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Merger MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

GroupDocs.Merger for Python via .NET allows you to stack multiple images into a single output image programmatically. Use ImageJoinOptions to control the output format and the direction in which images are joined — horizontally side by side or vertically one above the other.

The library supports JPG, PNG, BMP, and other common image formats.

Steps to merge JPEG images vertically

  1. Create an instance of the Merger class and pass the path to the first (base) image.
  2. Create an ImageJoinOptions instance specifying the target FileType and the ImageJoinMode.
  3. Call merger.join() with the path to each additional image and the join options.
  4. Call merger.save() with the desired output path.
from groupdocs.merger import Merger
from groupdocs.merger.domain import FileType
from groupdocs.merger.domain.options import ImageJoinOptions, ImageJoinMode

def merge_image_documents():
    # Load the first image as the merge base
    with Merger("./input.jpg") as merger:
        # Configure join options: output as JPEG, stack images vertically
        image_join_options = ImageJoinOptions(FileType.JPEG, ImageJoinMode.VERTICAL)
        # Append the second image with the join options applied
        merger.join("./input2.jpg", image_join_options)
        # Save the combined image
        merger.save("./output.jpg")

if __name__ == "__main__":
    merge_image_documents()

input.jpg is a sample file used in this example. Click here to download it.

input2.jpg is a sample file used in this example. Click here to download it.

Binary file (JPG, 65 KB)

Download full output

Explanation

  • Load base image: Merger("./input.jpg") opens the first image as the merge base inside a context manager.
  • ImageJoinOptions(FileType.JPEG, ImageJoinMode.VERTICAL): Specifies that the output should be a JPEG file and that images should be stacked vertically (top to bottom). Use ImageJoinMode.HORIZONTAL to place them side by side instead.
  • Append second image: merger.join("./input2.jpg", image_join_options) appends the second image according to the join options.
  • Save result: merger.save("./output.jpg") writes the merged image to disk.

Merge different image file formats

Merge Images Live Demo

GroupDocs.Merger offers the following free online tools to test its quality and accuracy:

API reference

See also