Merge JPG in PHP

High-speed and cross-platform PHP library for merging JPG images using PHP code

Merge JPG to JPG using Aspose.Slides

Aspose.Slides for PHP via Java is a powerful PHP library used to merge and manipulate presentations, images, and other files. When you merge JPG to JPG, you are effectively combining two images to get one picture.

Merge JPG to JPG in PHP

Using Aspose.Slides for PHP via Java , you can merge JPG files quickly with just a few lines of code

PHP code for merging JPG to JPG


<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
require_once("lib/aspose.slides.php");

$pres = new Presentation();
try
{
    $slide = $pres->getSlides()->get_Item(0);
    
    $filename1 = 'image1.jpg';
    $f1 = fopen($filename1, 'r');
    if ($f1) {
        $contents1 = fread($f1, filesize($filename1));
        fclose($f1);
    }

    $filename2 = 'image1.jpg';
    $f2 = fopen($filename2, 'r');
    if ($f2) {
        $contents2 = fread($f2, filesize($filename2));
        fclose($f2);
    }
    
    $image1 = $pres->getImages()->addImage($contents1);
    $slide->getShapes()->addPictureFrame(ShapeType::Rectangle, 0, 0, 360, 540, $image1);
    
    $image2 = $pres->getImages()->addImage($contents2);
    $slide->getShapes()->addPictureFrame(ShapeType::Rectangle, 360, 0, 360, 540, $image2);

    $img = $pres->getSlides()->get_Item(0)->getThumbnail(2, 2);
    $imageio = new Java("javax.imageio.ImageIO");
    $javafile = new Java("java.io.File", "merged-image.jpg");
    $imageio->write($img, "JPEG", $javafile);
}
finally
{
    if ($pres != null) $pres->dispose();
}
?>

How to merge JPG in PHP

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

  2. Add the library as a reference in your project.

  3. Create an instance of the Presentation class.

  4. Load the JPG files you want to merge as picture frames.

  5. Save the resulting JPG image.

Merge PDF Files Online

How to Merge PDF in Python

Merge other files

You can also combine files in other formats to get a single file