PhpPresentation imagecreatefromstring():数据不是可识别的格式 - PHP7.2
PhpPresentation imagecreatefromstring(): Data is not in a recognized format - PHP7.2
我正在尝试使用 PhpPresentation 阅读 sample.pptx
文件,使用他们文档中面向读者的简单说明,我得到:
imagecreatefromstring(): Data is not in a recognized format
我已检查我是否安装了 PHP7.2-gd 和所有其他依赖项。
我的代码:
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);
谁能帮我理解这个问题?
查看 the PHP source code, to have some insights about the "imagecreatefromstring" 函数后,我发现它只能处理以下图像格式:
- JPEG
- PNG
- 动图
- WBM
- GD2
- BMP
- WEBP
PHP 通过检查图像签名来识别 "imagecreatefromstring" 函数参数中包含的图像格式,如 here.
所述
当检测到未知签名时,会发出警告 "Data is not in a recognized format"。
因此,对于您遇到的错误,唯一合理的解释是 您的 PPTX 文件包含的图像不是上述格式之一。
您可以通过将扩展名从“.pptx”更改为“.zip”然后打开它来查看 PPTX 文件中图像的格式。
你应该看到这样的东西:
Archive: sample.pptx
Length Date Time Name
--------- ---------- ----- ----
5207 1980-01-01 00:00 [Content_Types].xml
...
6979 1980-01-01 00:00 ppt/media/image1.jpeg
6528 1980-01-01 00:00 ppt/media/image2.jpeg
178037 1980-01-01 00:00 ppt/media/image3.jpeg
229685 1980-01-01 00:00 ppt/media/image4.jpeg
164476 1980-01-01 00:00 ppt/media/image5.jpeg
6802 1980-01-01 00:00 ppt/media/image6.png
19012 1980-01-01 00:00 ppt/media/image7.png
32146 1980-01-01 00:00 ppt/media/image8.png
...
--------- -------
795623 74 files
如您所见,我的 sample.pptx 文件包含一些 JPEG 和 PNG 格式的图像。
也许您的示例文件包含一些带有矢量格式(WMF 或 EMF)图像的幻灯片;我不清楚(因为我在 the docs 中没有找到任何参考资料)是否支持这些格式。
最终你应该尝试使用其他 PPTX 文件,只是为了确保问题与特定文件无关(你可以在“test/resources/files”下找到一些)。
我搜索了 PowerPoint 文件支持的图像格式列表,但未能找到准确的答复。
我发现的唯一相关链接如下:
- ECMA 376 Open Office XML 1st Edition - Image Part
- ISO/IEC29500 的办公室实施信息
标准支持(2.1.32 第 1 部分第 15.2.14 节,图像部分,第 57/58 页)
- Images in Open XML documents(阅读页尾的评论)
- Question on OpenXML Developer Forum
这意味着 PPTX 文件中存在 TIFF 或 PICT (QuickDraw) 格式的图像也可能导致所考虑的错误。
在 open office 或 MS 中以 PPT 2007 格式再次保存您的 pptx Powerpoint.Its 格式 issue.You 正在用 2007 打开最新的 PPT 格式
我正在尝试使用 PhpPresentation 阅读 sample.pptx
文件,使用他们文档中面向读者的简单说明,我得到:
imagecreatefromstring(): Data is not in a recognized format
我已检查我是否安装了 PHP7.2-gd 和所有其他依赖项。
我的代码:
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);
谁能帮我理解这个问题?
查看 the PHP source code, to have some insights about the "imagecreatefromstring" 函数后,我发现它只能处理以下图像格式:
- JPEG
- PNG
- 动图
- WBM
- GD2
- BMP
- WEBP
PHP 通过检查图像签名来识别 "imagecreatefromstring" 函数参数中包含的图像格式,如 here.
所述
当检测到未知签名时,会发出警告 "Data is not in a recognized format"。
因此,对于您遇到的错误,唯一合理的解释是 您的 PPTX 文件包含的图像不是上述格式之一。
您可以通过将扩展名从“.pptx”更改为“.zip”然后打开它来查看 PPTX 文件中图像的格式。
你应该看到这样的东西:
Archive: sample.pptx
Length Date Time Name
--------- ---------- ----- ----
5207 1980-01-01 00:00 [Content_Types].xml
...
6979 1980-01-01 00:00 ppt/media/image1.jpeg
6528 1980-01-01 00:00 ppt/media/image2.jpeg
178037 1980-01-01 00:00 ppt/media/image3.jpeg
229685 1980-01-01 00:00 ppt/media/image4.jpeg
164476 1980-01-01 00:00 ppt/media/image5.jpeg
6802 1980-01-01 00:00 ppt/media/image6.png
19012 1980-01-01 00:00 ppt/media/image7.png
32146 1980-01-01 00:00 ppt/media/image8.png
...
--------- -------
795623 74 files
如您所见,我的 sample.pptx 文件包含一些 JPEG 和 PNG 格式的图像。
也许您的示例文件包含一些带有矢量格式(WMF 或 EMF)图像的幻灯片;我不清楚(因为我在 the docs 中没有找到任何参考资料)是否支持这些格式。
最终你应该尝试使用其他 PPTX 文件,只是为了确保问题与特定文件无关(你可以在“test/resources/files”下找到一些)。
我搜索了 PowerPoint 文件支持的图像格式列表,但未能找到准确的答复。
我发现的唯一相关链接如下:
- ECMA 376 Open Office XML 1st Edition - Image Part
- ISO/IEC29500 的办公室实施信息 标准支持(2.1.32 第 1 部分第 15.2.14 节,图像部分,第 57/58 页)
- Images in Open XML documents(阅读页尾的评论)
- Question on OpenXML Developer Forum
这意味着 PPTX 文件中存在 TIFF 或 PICT (QuickDraw) 格式的图像也可能导致所考虑的错误。
在 open office 或 MS 中以 PPT 2007 格式再次保存您的 pptx Powerpoint.Its 格式 issue.You 正在用 2007 打开最新的 PPT 格式