Free Support Forum - aspose.com

Convert ppt to images with php on Linux

Hi guys,

do you have some example php script of how to use Aspose.Slides to convert ppt slides to images from php on hosted Linux server?

Thank you,

Viktor

@viktor17,

Can you please share source file along with sample code so that we may further investigate to help you out.

I tried to start with script below, I found on the internet.
I replaced library name by “./lib/libAspose.Slides_clang.so”

$runtime->RegisterAssemblyFromFile("libraries/_bin/aspose/Aspose.Slides.dll", "Aspose.Slides");
$runtime->RegisterAssemblyFromFullQualifiedName("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing");

$sourcefile = "TestPresentation.ppt";

$presentation = $runtime->TypeFromName("Aspose.Slides.Presentation")->Instantiate($sourcefile);
$format = $runtime->TypeFromName("System.Drawing.Imaging.ImageFormat")->Png;

$x = 0;

/** @var \NetPhp\Core\NetProxyCollection */
$slides = $presentation->Slides->AsIterator();

foreach ($slides as $slide) {
  $bitmap = $slide->GetThumbnail(1, 1);
  $destinationfile ="./output/slide_{$x++}.png";
  $bitmap->Save($destinationfile, $format);
}

$presentation->Dispose();

@viktor17,

I have observed your requirements and an issue with ID SLIDESNET-41463 has been created in our issue tracking to investigate your requirements. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

@viktor17,

You have requested for sample to convert a PowerPoint slide to an image on Linux/PHP, and there’s no requirement to use a .NET version of Slides for this. Using .NET code on Linux via PHP is not a simple task. But there’s another much simpler option - use Slides for Java (instead of Slides.NET) and PHP/Java Bridge (https://sourceforge.net/projects/php-java-bridge/).

Then, you may be able to achieve your goal like following:

public function getThumbnail()
{
    $fileName = 'presentation.pptx';

    // Open source presentation
    $presentationSource = new Java('com.aspose.slides.Presentation', $fileName);

    // Get the slides of source presentation
    $sourcePresentationSlides = $presentationSource->getSlides();
    $numberOfSlides = java_values($presentationSource->size());

    //Iterating through all slides
    for ($i = 1; $i <= $numberOfSlides; $i++)
    {
        // Get presentation slide
        $slide = $sourcePresentationSlides->get_Item($i - 1);
       //Getting the thumbnail image of the slide of a specified size
        $image=$slide->getThumbnail(1f,1f);
        //Creating the ImageIO class object
        $ImageIO = new Java("javax.imageio.ImageIO");
        //Creating a file output stream to write the slide thumbnail
        $fostream=new Java("java.io.FileOutputStream","thumbnail.jpg");
        //Saving the thumbnail image in jpeg format
        $ImageIO->write($image,"jpeg",$fostream);
        $fostream->close();
    }

    // Get presentation
    $save_format = Java('com.aspose.slides.SaveFormat');
    $memoryStream = new Java('java.io.ByteArrayOutputStream');
    $presentationSource->save($memoryStream, $save_format->Pptx);
    $memoryStream->close();

}