Convert PNG to JPG in PHP

Powerful PowerPoint PHP library that helps in developing applications with the ability to create, merge, inspect, or convert Microsoft PowerPoint and OpenOffice presentation files without the use of any software like Microsoft or Open Office, Adobe PDF.

Convert PNG to JPG in PHP

Aspose.Slides for PHP via Java is a powerful PHP library for creating and manipulating presentation files. Moreover, it provides flexible ways to convert PNG to JPG. Using Aspose.Slides for PHP via Java, any developer or application can convert PNG to JPG files with just a few lines of PHP code.

As a modern document processing API, Aspose.Slides for PHP exports PNG files to JPG file formats quickly. Aspose PowerPoint library allows you to convert PNG to JPGs and many other file formats

Convert PNG to JPG using PHP

To convert the PNG to JPG, you will need to create Presentation from PNG file and save it as JPG.

PHP code for converting PNG into 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);
    
    $filename = 'image.png';
    $f = fopen($filename, 'r');
    if ($f) {
        $contents = fread($f, filesize($filename));
        fclose($f);
    }
    
    $image = $pres->getImages()->addImage($contents);
    $slide->getShapes()->addPictureFrame(ShapeType::Rectangle, 10, 10, 100, 100, $image);

    for ($i = 0; $i < java_values($pres->getSlides()->size()); $i++)
    {
        $bmp = $pres->getSlides()->get_Item($i)->getThumbnail(2, 2);
        $imageio = new Java("javax.imageio.ImageIO");
        $javafile = new Java("java.io.File", "slide_". $i .".jpg");
        $imageio->write($bmp, "JPG", $javafile);
    }
}
finally
{
    if ($pres != null) $pres->dispose();
}
?>

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

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

  1. Install Aspose.Slides for PHP via Java .

  2. Add a library reference (import the library) to your PHP project.

  3. Open the source PNG files in PHP.

  4. Save result as JPG file.

Free Online Converter

How to Convert PPT to HTML in Python

Convert PNG To Other Supported Formats

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