Merge JPG Images in PHP

Arrange multiple JPG images on a slide and render them as a single JPEG file with Aspose.Slides for PHP via Java.

Merge JPG Images using Aspose.Slides

Aspose.Slides for PHP via Java lets you arrange multiple JPG images on a presentation slide and render the composed slide as a single JPEG file. The example below places two JPG images side by side.

Merge JPG Images in PHP

Load the JPG files with Images::fromFile, add them to the slide with addPictureFrame, render the slide with getImage, and save the result with ImageFormat::Jpeg.

PHP code for merging JPG images

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);

    $firstSourceImage = Images::fromFile("image1.jpg");
    try {
        $firstPresentationImage = $presentation->getImages()->addImage($firstSourceImage);
    } finally {
        $firstSourceImage->dispose();
    }

    $secondSourceImage = Images::fromFile("image2.jpg");
    try {
        $secondPresentationImage = $presentation->getImages()->addImage($secondSourceImage);
    } finally {
        $secondSourceImage->dispose();
    }

    $slide->getShapes()->addPictureFrame(
        ShapeType::Rectangle, 0, 0, 360, 270, $firstPresentationImage);
    $slide->getShapes()->addPictureFrame(
        ShapeType::Rectangle, 360, 0, 360, 270, $secondPresentationImage);

    $slideImage = $slide->getImage(1.0, 1.0);
    try {
        $slideImage->save("merged-image.jpg", ImageFormat::Jpeg);
    } finally {
        $slideImage->dispose();
    }
} finally {
    $presentation->dispose();
}

How to merge JPG images in PHP

  1. Install Aspose.Slides for PHP via Java. See Installation .

  2. Configure Aspose.Slides in your PHP project.

  3. Create a Presentation and access its first slide through a variable.

  4. Load the JPG files with Images::fromFile and place them on the slide with addPictureFrame.

  5. Render the slide with getImage and save the result with ImageFormat::Jpeg.

Merge Other Files

You can also combine files in other supported formats.