如何使用 ImageMagick、Ghostscript、Windows Vista/7 x64 安装、测试、转换、调整 PDF 大小

发布于 2024-09-10 06:32:54 字数 83 浏览 7 评论 0原文

我在让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初见你 2024-09-17 06:32:54

我刚刚花了过去三个小时让 ImageMagick 与 PHP 完美配合,将 PDF 转换为 JPG。我不想自己在本地记录它,而是想把它写在这里,把所有的流行语和我搞砸的东西写下来,这样下一个菜鸟就可以节省一些时间。

在 Windows 7 x64 和 Vista x64 两个操作系统上进行测试,使用 PHP 5.2.8 和 Apache 2.2.11。

您需要 Ghostscript 和 ImageMagick。我有 gs871w64.exeImageMagick-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 - 编写此脚本:

$out = shell_exec("convert blah.pdf blah2.jpg 2>&1");
echo $out;

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 and ImageMagick-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 have test.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:

$out = shell_exec("convert blah.pdf blah2.jpg 2>&1");
echo $out;

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.

怎言笑 2024-09-17 06:32:54

Steve 已经提供了有关从 PHP 运行 ImageMagick 命令行版本的指南。在安装 ImageMagick 的 扩展 版本方面有类似的经验后,我想详细说明一下不同组件如何协同工作。

Imagick(PHP 扩展)

首先您需要 PHP 扩展。它基本上是 PHP 和 ImageMagick 函数之间的适配器。

但是,这还不够。 php_imagick.dll 不包含任何 ImageMagick 功能,并且与扩展捆绑在一起的 CORE_RL_... DLL 不完整。您还需要 ImageMagick 版本中的更多 DLL。

理论上版本不必完全匹配,但显然在 ImageMagick 6.8.1 和 6.8.8 之间,函数 MagickGetImageMatte 已从 DLL 中删除,因此最安全的方法是找到完全相同的版本Imagick 扩展所针对的 ImageMagick 版本:

  • 在 Windows 资源管理器中,请参阅捆绑的 CORE_RL_wand_.dll 的“属性”→“详细信息”,以查找该扩展所针对的 ImageMagick 版本。 (您还应该能够在 phpinfo 中找到此信息。)
  • 下载确切的 ImageMagick 版本,例如从 http://windows.php.net/downloads/pecl/deps/(感谢这个人 获取链接)
  • 复制所有 DLL从 ImageMagick ZIP 到 php5(n)ts.dll(Apache 的 PHP 引擎)所在的同一目录

没有必要安装 ImageMagick。事实上,如果您的 PATH 中碰巧有不兼容的 ImageMagick,PHP 扩展可能会失败。

Ghostscript

这适用于 ImageMagick 的命令行版本(convert)和上述 PHP 扩展。

要读取 Postscript 系列的文件,需要 Ghostscript。

ImageMagick 将按照以下步骤查找 Ghostscript:

  • 如果注册表中有一个 GS_DLL 条目,指向 gswin32.dll 的路径,它将使用该条目并忽略委托共。
  • 否则它将咨询其“代表”。似乎有一个硬编码的回退,但您可以通过将 delegates.xml 放在 php5(n)ts.dllconvert.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.

  • Choose a version from http://windows.php.net/downloads/pecl/releases/imagick/
  • Download the extension matching your PHP version in architecture (probably 32bit), thread-safe-ness and compiler (VC9 or VC11), see phpinfo
  • Copy php_imagick.dll from the extension ZIP to the PHP extension directory

However, this is not enough. The php_imagick.dll does not contain any ImageMagick functionality and the CORE_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:

  • In Windows Explorer, see Properties → Details of the bundled CORE_RL_wand_.dll to find the version of ImageMagick that this extension is made for. (You should also be able to find this information in phpinfo.)
  • Download that exact ImageMagick version, for example from http://windows.php.net/downloads/pecl/deps/ (thanks to this guy for the link)
  • Copy all the DLLs from the ImageMagick ZIP to the same directory where php5(n)ts.dll (the PHP engine for Apache) is

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:

  • If there is a GS_DLL entry in the registry, pointing to the path of gswin32.dll, it will use that one and ignore the delegates altogether.
  • Otherwise it will consult it's "delegates". There seems to be a hardcoded fallback, but you can override it by putting a delegates.xml next to php5(n)ts.dll or convert.exe respectively or in ~\.magick.
  • If it finds the string @PS_Delegate@ in the delegate, it will replace it with gswin32c.exe and then continue looking for that EXE in the PATH. You can replace this string with the full path to gswin32c.exe or even gswin64c.exe that ImageMagick should call.
当梦初醒 2024-09-17 06:32:54

我遇到了同样的问题,我安装了适用于 Windows(64 位)的 Ghostscript 9.54.0,它解决了我的问题:

按照以下步骤操作:

  1. 转到 https://www.ghostscript.com/download.html 单击“Postscript 和 PDF 解释器/渲染器:”下的 Ghostscript。它打开了一个新页面: https://www.ghostscript.com/download/gsdnld.html< /a>


  2. 从该页面安装了适用于 Windows 的 Ghostscript 9.54.0(64 位)。

  3. 下载后安装在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:

  1. 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

  2. From the page installed Ghostscript 9.54.0 for Windows (64 bit).

  3. After downloading install it on the windows machine.

After that restated kernel and re-executed jupyter notebook.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文