在 Ubuntu 18 上使用 Imagemagick 转换 PDF 时出错

在 Ubuntu 18 上使用 Imagemagick 转换 PDF 时出错

在 Azure 上使用 Bitnami WordPress 堆栈的 Ubuntu 18.04.4 LTS 上,我尝试让 Imagemagick 和 Ghostscript 运行,以便 WordPress 创建 PDF 缩略图。一个简单的转换测试给出了错误。当我搜索错误消息时,它们让我越来越深入地陷入各种兔子洞,包括缺少库、手动添加符号链接、从源代码编译等。运行一个流行的图像转换程序似乎不应该那么难。我错过了什么?

以下是版本和失败的测试:

/tmp$ sudo apt update
All packages are up to date.
/tmp$ sudo apt install imagemagick
imagemagick is already the newest version (8:6.9.7.4+dfsg-16ubuntu6.8).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
/tmp$ sudo apt install ghostscript
ghostscript is already the newest version (9.26~dfsg+0-0ubuntu0.18.04.12).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

/tmp$ which convert
/opt/bitnami/common/bin/convert
/tmp$ convert -version
Version: ImageMagick 6.9.8-3 Q16 x86_64 2019-04-03 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl png tiff wmf xml zlib

/tmp$ which ghostscript
/usr/bin/ghostscript
/tmp$ gs -version
GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.

/tmp$ convert -verbose resume.pdf resume.jpg
'gs' -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72'  '-sOutputFile=/tmp/magick-38144ceME6-csnc4X%d' '-f/tmp/magick-38144tpfIz6n76qfI' '-f/tmp/magick-38144AH22zQfdNQqs'
gs: /opt/bitnami/common/lib/libtiff.so.5: no version information available (required by /usr/lib/x86_64-linux-gnu/libgs.so.9)
gs: symbol lookup error: /usr/lib/x86_64-linux-gnu/libgs.so.9: undefined symbol: FT_Property_Set
.convert.bin: no images defined `resume.jpg' @ error/convert.c/ConvertImageCommand/3258.

编辑根据评论的要求:

~$ echo $LD_LIBARY_PATH

~$ ldd $(which conver)
ldd: missing file arguments
Try `ldd --help' for more information.
~$ ldd $(which convert)
        not a dynamic executable
~$ ldd /usr/bin/ghostscript
        linux-vdso.so.1 (0x00007fffc5be3000)
        libgs.so.9 => /usr/lib/x86_64-linux-gnu/libgs.so.9 (0x00007f3614e95000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3614aa4000)
        libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f361482d000)
        libcupsimage.so.2 => /usr/lib/x86_64-linux-gnu/libcupsimage.so.2 (0x00007f3614624000)
        libcups.so.2 => /usr/lib/x86_64-linux-gnu/libcups.so.2 (0x00007f3614398000)
        libijs-0.35.so => /usr/lib/x86_64-linux-gnu/libijs-0.35.so (0x00007f3614192000)
        libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f3613f60000)
        libjbig2dec.so.0 => /usr/lib/x86_64-linux-gnu/libjbig2dec.so.0 (0x00007f3613d48000)
        libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f3613ae0000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f36138c3000)
        liblcms2.so.2 => /usr/lib/x86_64-linux-gnu/liblcms2.so.2 (0x00007f361366b000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f36132cd000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f36130c9000)
        libidn.so.11 => /lib/x86_64-linux-gnu/libidn.so.11 (0x00007f3612e96000)
        libpaper.so.1 => /usr/lib/x86_64-linux-gnu/libpaper.so.1 (0x00007f3612c92000)
        libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f3612a4d000)
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f3612799000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f361257a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3616241000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f3612354000)
        libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f3612146000)
        libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f3611efb000)
        libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f3611b95000)
        libavahi-common.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-common.so.3 (0x00007f3611989000)
        libavahi-client.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-client.so.3 (0x00007f3611778000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f3611546000)
        libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f3611270000)
        libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f361103e000)
        libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f3610e3a000)
        libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f3610c2f000)
        libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f3610900000)
        libidn2.so.0 => /usr/lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f36106e3000)
        libunistring.so.2 => /usr/lib/x86_64-linux-gnu/libunistring.so.2 (0x00007f3610365000)
        libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f3610152000)
        libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f360ff1c000)
        libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f360fce8000)
        libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f360fa67000)
        libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f360f81a000)
        libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f360f616000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f360f3fb000)
        libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f360f1f3000)
        libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f360ef6f000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f360ed67000)
        liblz4.so.1 => /usr/lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f360eb4b000)
        libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f360e82f000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f360e61a000)

答案1

在 Bitnami 论坛上发布此问题后,我收到了建议卸载 Ghostscript 9.26 并将 9.27 二进制文件直接从 Github 上传到服务器路径。令我惊讶的是,这立即允许 Imagemagick 工作。WordPress 中的 PDF 缩略图生成也可以正常工作。

基于这个帖子,下面是我用来卸载 Ghostscript 并从 Github 获取 9.27 二进制文件的命令:

$ sudo apt remove ghostscript
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fonts-droid-fallback fonts-noto-mono libcupsfilters1 libcupsimage2 libgs9 libgs9-common
  libijs-0.35 libjbig2dec0 libpaper-utils libpaper1 poppler-data
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  ghostscript
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 229 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 128918 files and directories currently installed.)
Removing ghostscript (9.26~dfsg+0-0ubuntu0.18.04.12) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
~$ $ cd /tmp && curl -LO https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs927/ghostscript-9.27-linux-x86_64.tgz
$: command not found
~$ cd /tmp && curl -LO https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs927/ghostscript-9.27-linux-x86_64.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   644  100   644    0     0   2730      0 --:--:-- --:--:-- --:--:--  2775
100 11.5M  100 11.5M    0     0  7733k      0  0:00:01  0:00:01 --:--:-- 21.9M
/tmp$ tar -xzf ghostscript-9.27-linux-x86_64.tgz
/tmp$ sudo mv ghostscript-9.27-linux-x86_64/gs-927-linux-x86_64 /usr/local/bin/gs
/tmp$ rm -r ghostscript-9.27-linux-x86_64 ghostscript-9.27-linux-x86_64.tgz
/tmp$ gs -version
GPL Ghostscript 9.27 (2019-04-04)
Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
/tmp$ convert -verbose resume.pdf resume.jpg
'gs' -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72'  '-sOutputFile=/tmp/magick-27002C4cvCbSgCyYC%d' '-f/tmp/magick-27002GcI2PwMTOpvp' '-f/tmp/magick-2700234-pb9vPGw2b'
/tmp/magick-27002C4cvCbSgCyYC1 PNG 594x774 594x774+0+0 8-bit sRGB 28.3KB 0.030u 0:00.039
/tmp/magick-27002C4cvCbSgCyYC2 PNG 594x774 594x774+0+0 8-bit sRGB 25.3KB 0.040u 0:00.030
resume.pdf[0] PDF 594x774 594x774+0+0 16-bit sRGB 28.3KB 0.040u 0:00.030
resume.pdf[1] PDF 594x774 594x774+0+0 16-bit sRGB 28.3KB 0.000u 0:00.000
resume.pdf=>resume-0.jpg[0] PDF 594x774 594x774+0+0 16-bit Bilevel Gray 133KB 0.030u 0:00.050
resume.pdf=>resume-1.jpg[1] PDF 594x774 594x774+0+0 16-bit Bilevel Gray 122KB 0.060u 0:00.079

相关内容