如何使用 ImageMagick、Ghostscript、Windows Vista/7 x64 安装、测试、转换、调整 PDF 大小
我在让 ImageMagick 和 Ghostscript 协同工作时遇到了麻烦 - 从安装、测试到实际使用该软件,一切似乎都很困难。有人有什么建议吗?
I'm having trouble with getting ImageMagick and Ghostscript to work together - everything seems difficult, from installation, to testing, to actually using the software. Does anyone have any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚花了过去三个小时让 ImageMagick 与 PHP 完美配合,将 PDF 转换为 JPG。我不想自己在本地记录它,而是想把它写在这里,把所有的流行语和我搞砸的东西写下来,这样下一个菜鸟就可以节省一些时间。
在 Windows 7 x64 和 Vista x64 两个操作系统上进行测试,使用 PHP 5.2.8 和 Apache 2.2.11。
您需要 Ghostscript 和 ImageMagick。我有
gs871w64.exe
和ImageMagick-6.6.3-0-Q16-windows-x64-dll.exe
。进行 ImageMagick 的基本安装(我现在将其称为 IM)。仔细检查系统路径变量,以确保您可以从任何地方进行 IM。它应该指向 IM 目录。在
cmd
中使用以下行测试安装:convert test.gif test.jpg
(假设您有test.gif
)。工作正常。测试 PDF 转换(
convert test.pdf test.jpg
)。您应该收到一条有关“gswin32c.exe”和“Postscript delegate failed”和“missing an image filename”的(长)消息。这意味着 IM 找不到 PDF“翻译器”。你需要 Ghostscript。安装 Ghostscript(我现在称之为 GS)。由于某种原因我不得不这样做两次才采取。将 GS 文件夹中的“bin”地址添加到系统变量中。使用
gswin32 test.pdf
测试安装,您应该会看到您的文件在 GS 查看器中弹出。重要提示:gs 在 Windows 中不起作用('gs' 不被识别为内部或外部命令、可操作程序或批处理文件。
)。您需要使用gswin32。回到 IM 测试:
convert test.pdf test.jpg
现在应该可以工作了。现在转到 PHP - 编写此脚本:
2>&1
将把所有错误移至标准输出,以便您可以更好地诊断:)。现在,您的 PHP 脚本可能会在 cmd 提示符下运行,但是当您在浏览器中运行它时什么也不会发生。拍拍额头,重启Apache。pant 我知道,这很详尽,而且可能很简单。但这是大约 20 页的半有用线索的总结,希望对您有所帮助。
I've just spent the last three hours getting ImageMagick to play nicely with PHP for a PDF to JPG convert. Instead of documenting it myself locally, I figured I'd write it up here, with all the buzzwords and things I screwed up, so the next noob can save some time.
Tested on two OSs,Windows 7 x64 and Vista x64, with PHP 5.2.8 and Apache 2.2.11.
You'll need Ghostscript and ImageMagick. I got
gs871w64.exe
andImageMagick-6.6.3-0-Q16-windows-x64-dll.exe
.Do a basic install of ImageMagick (I'll call it IM now). Double check the system path variable to ensure you can IM from anywhere. It should point to the IM directory. Test the installation with this line in
cmd
:convert test.gif test.jpg
(assuming you havetest.gif
). Works OK.Test a PDF convert (
convert test.pdf test.jpg
). You should get a (long) message about "gswin32c.exe" and "Postscript delegate failed" and "missing an image filename". That means IM can't find a PDF 'translator'. You need Ghostscript.Install Ghostscript (I'll call it GS now). I had to do it twice for some reason before it took. Add the 'bin' address in the GS folder to the system variable. Test the installation with
gswin32 test.pdf
and you should see your file pop up in the GS viewer. Important note: gs doesn't work in Windows ('gs' is not recognized as an internal or external command, operable program, or batch file.
). You need to use gswin32.Back to the IM test:
convert test.pdf test.jpg
should work now.Now over to PHP - write up this script:
The
2>&1
will move all errors into the standard output so you can better diagnose stuff :). Now, your PHP script may run in the cmd prompt, but nothing happens when you run it in a browser. Smack your forehead and restart Apache.pant Exhaustive and probably elementary, I know. But a hopefully helpful summary of approximately 20 pages of semi-helpful clues.
Steve 已经提供了有关从 PHP 运行 ImageMagick 命令行版本的指南。在安装 ImageMagick 的 扩展 版本方面有类似的经验后,我想详细说明一下不同组件如何协同工作。
Imagick(PHP 扩展)
首先您需要 PHP 扩展。它基本上是 PHP 和 ImageMagick 函数之间的适配器。
php_imagick.dll
到 PHP 扩展目录但是,这还不够。
php_imagick.dll
不包含任何 ImageMagick 功能,并且与扩展捆绑在一起的CORE_RL_...
DLL 不完整。您还需要 ImageMagick 版本中的更多 DLL。理论上版本不必完全匹配,但显然在 ImageMagick 6.8.1 和 6.8.8 之间,函数
MagickGetImageMatte
已从 DLL 中删除,因此最安全的方法是找到完全相同的版本Imagick 扩展所针对的 ImageMagick 版本:没有必要安装 ImageMagick。事实上,如果您的 PATH 中碰巧有不兼容的 ImageMagick,PHP 扩展可能会失败。
Ghostscript
这适用于 ImageMagick 的命令行版本(
convert
)和上述 PHP 扩展。要读取 Postscript 系列的文件,需要 Ghostscript。
ImageMagick 将按照以下步骤查找 Ghostscript:
GS_DLL
条目,指向gswin32.dll
的路径,它将使用该条目并忽略委托共。delegates.xml
放在php5(n)ts.dll
或convert.exe< 旁边来覆盖它/code> 分别或在
~\.magick
中。@PS_Delegate@
,它将用gswin32c.exe
替换它,然后继续在 PATH 中查找该 EXE。您可以将此字符串替换为 ImageMagick 应调用的gswin32c.exe
甚至gswin64c.exe
的完整路径。Steve already provided a guide on running the command line version of ImageMagick from PHP. After having a similar experience installing the extension version of ImageMagick, I'd like to elaborate a bit on how the different components work together.
Imagick (the PHP extension)
First you'll need the PHP extension. It's basically an adapter between PHP and the ImageMagick functions.
php_imagick.dll
from the extension ZIP to the PHP extension directoryHowever, this is not enough. The
php_imagick.dll
does not contain any ImageMagick functionality and theCORE_RL_...
DLLs that come bundled with the extension are not complete. You're gonna need some more DLLs from an ImageMagick release as well.Theoretically the version doesn't have to match exactly, but apparently somewhere between ImageMagick 6.8.1 and 6.8.8 the function
MagickGetImageMatte
has been removed from the DLLs, so the safest way is to find the exact same ImageMagick release that the Imagick extension was build for:It is not necessary to install ImageMagick. In fact, if you happen to have an incompatible ImageMagick in your PATH, the PHP extension might fail.
Ghostscript
This applies to both the command line version of ImageMagick (
convert
) and the PHP extension described above.For reading files of the Postscript family, Ghostscript is needed.
ImageMagick will find Ghostscript following these steps:
GS_DLL
entry in the registry, pointing to the path ofgswin32.dll
, it will use that one and ignore the delegates altogether.delegates.xml
next tophp5(n)ts.dll
orconvert.exe
respectively or in~\.magick
.@PS_Delegate@
in the delegate, it will replace it withgswin32c.exe
and then continue looking for that EXE in the PATH. You can replace this string with the full path togswin32c.exe
or evengswin64c.exe
that ImageMagick should call.我遇到了同样的问题,我安装了适用于 Windows(64 位)的 Ghostscript 9.54.0,它解决了我的问题:
按照以下步骤操作:
转到 https://www.ghostscript.com/download.html 单击“Postscript 和 PDF 解释器/渲染器:”下的 Ghostscript。它打开了一个新页面: https://www.ghostscript.com/download/gsdnld.html< /a>
从该页面安装了适用于 Windows 的 Ghostscript 9.54.0(64 位)。
下载后安装在Windows机器上。
之后重述内核并重新执行 Jupyter Notebook。
I was facing the same issue I installed Ghostscript 9.54.0 for Windows (64 bit) it solved my issue:
Followed the following steps:
Go to https://www.ghostscript.com/download.html clicked Ghostscript under "Postscript and PDF interpreter/renderer:". It opened a new page: https://www.ghostscript.com/download/gsdnld.html
From the page installed Ghostscript 9.54.0 for Windows (64 bit).
After downloading install it on the windows machine.
After that restated kernel and re-executed jupyter notebook.