I am trying to use PhpPresentation to read a sample.pptx
file using the simple instructions for readers in their docs and I am getting:
imagecreatefromstring(): Data is not in a recognized format
I have checked that I have PHP7.2-gd installed and all of the other dependencies.
My Code:
require_once 'vendor/autoload.php';
use \PhpOffice\PhpPresentation\PhpPresentation;
use \PhpOffice\PhpPresentation\IOFactory;
use \PhpOffice\PhpPresentation\Style\Color;
use \PhpOffice\PhpPresentation\Style\Alignment;
$oReader = IOFactory::createReader('PowerPoint2007');
$data = $oReader->load(__DIR__ . '/sample.pptx');
var_dump($data);
Can anybody help me understand the issue?
After peeking into the PHP source code, to have some insights about the "imagecreatefromstring" function, I've discovered that it handles only the following image formats:
PHP recognizes the format of the image contained in the argument of the "imagecreatefromstring" function by checking the image signature, as explained here.
When an unknown signature is detected, the warning "Data is not in a recognized format" is raised.
Therefore, the only plausible explanation for the error that you are experiencing is that your PPTX file contains an image that is not in one of the above formats.
You can view the format of the images inside your PPTX file by changing its extension from ".pptx" to ".zip" and then opening it.
You should see something like this:
As you can see, my sample.pptx file contains some images in JPEG and PNG format.
Maybe your sample file contains some slides with images in a vector format (WMF or EMF); it's unclear to me (since I didn't find any reference in the docs) if those formats are supported or not. Eventually you should try with other PPTX files, just to make sure that the problem is not related to a specific one (you can find some under "test/resources/files").
I've searched for a list of the supported image formats for PowerPoint files, but I haven't been able to find a precise response.
The only relevant links that I've found are the following:
This means that also the presence in the PPTX file of an image in the TIFF or PICT (QuickDraw) format could lead to the error under consideration.