Convert Image to JPG in PHP

Add an image to a slide and render it in JPEG format with Aspose.Slides for PHP via Java.

Convert Image to JPG in PHP

Aspose.Slides for PHP via Java can add supported raster or vector images to presentation slides and render the slides in JPEG format.

The modern image API uses Images::fromFile to load the source image, getImage to render the slide, and ImageFormat::Jpeg to select JPEG output.

Convert Image to JPG using PHP

To convert an image to JPG, add it to a Presentation, place it on a slide, render the slide with getImage, and save the rendered image with ImageFormat::Jpeg.

PHP code for converting Image into JPG

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

    $sourceImage = Images::fromFile("input.png");
    try {
        $embeddedImage = $presentation->getImages()->addImage($sourceImage);
    } finally {
        $sourceImage->dispose();
    }

    $imageWidth = java_values($embeddedImage->getWidth());
    $imageHeight = java_values($embeddedImage->getHeight());

    $slide->getShapes()->addPictureFrame(
        ShapeType::Rectangle, 0, 0, $imageWidth, $imageHeight, $embeddedImage);

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

How to convert Image to JPG using Aspose.Slides for PHP API

These are the steps to convert Image to JPG in PHP.

  1. Install Aspose.Slides for PHP via Java .

  2. Configure Aspose.Slides in your PHP project.

  3. Create a Presentation, access its first slide, and load the source image with Images::fromFile.

  4. Add the image to the presentation, place it on the slide with addPictureFrame, render it with getImage, and save it with ImageFormat::Jpeg.

Free Online Converter

Try our free Conversion app

Convert Image To Other Supported Formats

You can also convert Image and save to other file formats. See all supported formats below: