由于“无图像定义”错误,无法将PDF转换为图像


71

我有以下PDF文件: http://www.fmwconcepts.com/misc_tests/pdf_tests/test.pdf

但是,当我试图通过以下方式转换它:

$ convert test.pdf test.png

我有以下错误:

convert: no images defined `test.png' @ error/convert.c/ConvertImageCommand/3187.

我有以下版本:

$ brew info libpng
libpng: stable 1.6.13 (bottled)

$ brew info libjpeg
jpeg: stable 8d (bottled)

$ brew info imagemagick
imagemagick: stable 6.8.9-7 (bottled), HEAD
http://www.imagemagick.org
/usr/local/Cellar/imagemagick/6.8.9-1 (1432 files, 22M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/imagemagick.rb
==> Dependencies
Build: xz ✔, pkg-config ✔
Required: libtool ✔
Recommended: jpeg ✔, libpng ✔, freetype ✔
Optional: fontconfig ✔, libtiff ✔, little-cms ✔, little-cms2 ✔, libwmf ✘, librsvg ✘, liblqr ✘, openexr ✘, ghostscript ✘, webp ✘

我有以下调试日志:

$ convert test.pdf test.png -debug all
2014-10-01T15:29:39+01:00 0:00.000 0.000u 6.8.9 Configure convert[58320]: utility.c/ExpandFilenames/944/Configure
  Command line: convert {test.pdf} {test.png} {-debug} {all}
2014-10-01T15:29:39+01:00 0:00.000 0.000u 6.8.9 Configure convert[58320]: configure.c/GetConfigureOptions/679/Configure
  Searching for configure file: "/usr/local/Cellar/imagemagick/6.8.9-1/share/ImageMagick-6/coder.xml"
...
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Module convert[58320]: module.c/OpenModule/1268/Module
  Searching for module "PNG" using filename "png.la"
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Module convert[58320]: module.c/GetMagickModulePath/554/Module
  Searching for coder module file "png.la" ...
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Module convert[58320]: module.c/OpenModule/1277/Module
  Opening module at path "/usr/local/Cellar/imagemagick/6.8.9-1/lib/ImageMagick//modules-Q16/coders/png.la"
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Module convert[58320]: module.c/OpenModule/1304/Module
  Method "RegisterPNGImage" in module "PNG" at address 0x10a9fdb60
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Module convert[58320]: module.c/OpenModule/1318/Module
  Method "UnregisterPNGImage" in module "PNG" at address 0x10aa0785d
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Policy convert[58320]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Path; rights=Read; pattern="test.png" ...
...
2014-10-01T15:29:39+01:00 0:00.020 0.010u 6.8.9 Configure convert[58320]: locale.c/LoadLocaleCache/1186/Configure
  Loading locale configure file "/usr/local/Cellar/imagemagick/6.8.9-1/share/ImageMagick-6/english.xml" ...
2014-10-01T15:29:39+01:00 0:00.020 0.020u 6.8.9 Exception convert[58320]: blob.c/OpenBlob/2657/Exception
  unable to open image `test.png': No such file or directory
2014-10-01T15:29:39+01:00 0:00.020 0.020u 6.8.9 Cache convert[58320]: cache.c/DestroyPixelCache/962/Cache
  destroy 
2014-10-01T15:29:39+01:00 0:00.020 0.020u 6.8.9 Policy convert[58320]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Coder; rights=Read; pattern="PNG" ...
2014-10-01T15:29:39+01:00 0:00.030 0.020u 6.8.9 Coder convert[58320]: png.c/ReadPNGImage/4015/Coder
  Enter ReadPNGImage()
2014-10-01T15:29:39+01:00 0:00.030 0.020u 6.8.9 Policy convert[58320]: policy.c/IsRightsAuthorized/574/Policy
  Domain: Path; rights=Read; pattern="test.png" ...
2014-10-01T15:29:39+01:00 0:00.030 0.020u 6.8.9 Exception convert[58320]: blob.c/OpenBlob/2657/Exception
  unable to open image `test.png': No such file or directory
2014-10-01T15:29:39+01:00 0:00.030 0.020u 6.8.9 Exception convert[58320]: png.c/ReadPNGImage/4021/Exception
  unable to open file `test.png'

但没有表现出任何明显的东西。并且看起来这个调试日志的行为与没有完全不同 -debug,因为原来的错误不存在。见 完整的日志

有类似的问题 http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22466 ,但我不太明白解决方案是什么。

Answers:


81

您缺少可选的Ghostscript依赖项 gs - 如果要转换PDF文件,则不可选。

如果 which gs 没有解析为ghostscript二进制文件(例如,你有一个同名的别名),编辑Ghostscript的路径 delegates.xml


在我的情况下,我安装了Ghostscript但是 gs 命令被我写的脚本隐藏了 git status。有没有办法为ImageMagick提供完整的路径 gs 二进制,以便我不必删除我的脚本(或别名)?
Sridhar-Sarnobat

2
您需要编辑文件delegates.xml并指定备用位置。
dlemstra

debian / ubuntu:apt-get install ghostscript
Nadir

60

你也可以尝试:

  1. brew uninstall ghostscript
  2. brew install ghostscript

这为我解决了这个问题。


这就是诀窍!
line-o

-1

我遇到了类似的问题。上面的修复程序对我没有任何作用,但看起来像ImageMagick正在使用 html2ps 内部。

所以,解决方案就是安装它。我不是OS X,所以对我来说解决方案是:

apt install html2ps

希望这会对某人有所帮助。


apt 要么 apt-get
kenorb

1
如果你有的话。它是apt-get的替代品。
mlissner

ImageMagick在内部使用html2ps将pdf转换为png吗?
rogerdpack
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.