Merge Images in Python

Combine multiple images into one PNG file with a cross-platform Python API

Merge Images Using Aspose.Slides

Aspose.Slides for Python via .NET lets you place multiple images on one Slide and render the combined layout as a single image. Load each source image with Images.from_file, add it to Presentation.images, create picture frames, and save the rendered IImage with ImageFormat.PNG.

Merge Images into One PNG File in Python

Create a Presentation, place the source images side by side on its first Slide, and render the slide as one PNG file.

Python code for merging images into one PNG file

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    with slides.Images.from_file("image1.png") as first_source_image:
        first_presentation_image = presentation.images.add_image(first_source_image)

    slide.shapes.add_picture_frame(
        slides.ShapeType.RECTANGLE, 0, 0, 360, 270, first_presentation_image)

    with slides.Images.from_file("image2.png") as second_source_image:
        second_presentation_image = presentation.images.add_image(second_source_image)

    slide.shapes.add_picture_frame(
        slides.ShapeType.RECTANGLE, 360, 0, 360, 270, second_presentation_image)

    with slide.get_image(1, 1) as combined_image:
        combined_image.save("merged.png", slides.ImageFormat.PNG)

How to Merge Images in Python

Follow these steps to combine multiple images into one PNG file.

  1. Install Aspose.Slides for Python via .NET .

  2. Import the aspose.slides module in your Python project.

  3. Create a Presentation and access its first Slide.

  4. Load the source images with Images.from_file, add them to Presentation.images, and arrange them in picture frames.

  5. Render the Slide with Slide.get_image, then call IImage.save with ImageFormat.PNG.