未捕获异常'ImagickException',消息为“无法读取文件”。

3
我是您的助手,下面为您翻译内容:

我在使用Imagick读取文件时遇到了问题。我已经成功安装了Imagick和Ghostscript扩展。

这是我的操作步骤:

<?php

    $im = new Imagick();
    $im->setResolution(300, 300);
    $im->readImage('/Applications/MAMP/htdocs/mywebsite/wp-content/plugins/myplugin/uploads/magazine_cover.pdf[0]');
    $im->setImageFormat('jpg');
    header('Content-Type: image/jpeg');
    echo $im;

?>

我遇到了以下错误:

Fatal error: Uncaught exception 'ImagickException' with message 'Failed to read the file' in /Applications/MAMP/htdocs/imagick.php on line 10

当我尝试在终端中执行以下命令时:

convert magazine_cover.pdf magazine_cover.jpeg

我收到了一个警告:

**** Warning: considering '0000000000 XXXXX n' as a free entry.

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.11.3 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

但是他创建了jpeg格式的图片...为什么在浏览器中无法使用?


可能是重复问题 [链接]https://dev59.com/AYHba4cB1Zd3GeqPMRFR[/链接] - isnisn
@isnisn:我看了那个主题并尝试使用'[0]',而且我的文件是可读的,所以没有解决方案.. - nielsv
我假设您已经检查了文件权限和用户/组? - isnisn
@isnisn:文件权限设置为777。你说的用户:组是什么意思? - nielsv
@nielsv 你修复了吗?我也遇到了同样的问题。文件可读,文件存在,路径正确,但仍然抛出错误。 - hfingler
1个回答

0

好的,这个警告是由Ghostscript生成的,它表示您的PDF文件在技术上不合法,但是除非存在更多问题,否则应该可以正常处理。

我建议您找出ImageMagick要传递给Ghostscript的命令,并在命令行上尝试运行它。如果能正常工作,那么问题很可能出在IM的端口,否则问题就是Ghostscript不喜欢您的PDF文件。命令行可能会提供更多信息。即使没有,有了这些信息和文件,您也可以打开一个Ghostscript错误报告并进行修复(如果可能)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接