【问题标题】:Uncaught exception 'ImagickException' with message 'Failed to read the file'未捕获的异常“ImagickException”,消息“读取文件失败”
【发布时间】:2016-05-19 13:18:35
【问题描述】:

我在使用 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;

?>

我收到了错误:

致命错误:带有消息的未捕获异常“ImagickException” /Applications/MAMP/htdocs/imagick.php 中的“读取文件失败” 第 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 ... 。为什么这在浏览器中不起作用?

【问题讨论】:

  • @isnisn:我看过那个话题并试图做 . '[0]' 。我的文件也是可读的,所以没有解决方案..
  • 我假设您已经检查了文件权限和用户:组?
  • @isnisn:文件权限在 777 上。用户:组是什么意思?
  • @nielsv 你解决了吗?我有同样的问题。文件可读,文件存在,路径正确,依然报错。

标签: php image pdf ghostscript imagick


【解决方案1】:

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

我建议你找出 ImageMagick 传递给 Ghostscript 的命令并在命令行上尝试。如果它有效,那么问题很可能出现在 IM 端,否则问题是 Ghostscript 不喜欢你的 PDF 文件。命令行可能会为您提供更多信息。即使它没有该信息和文件,您也可以打开 Ghostscript 错误报告并且可以修复它(如果可能的话)。

【讨论】:

    猜你喜欢
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    相关资源
    最近更新 更多