【问题标题】:How does ImageMagick pass options to cwebp LinuxImageMagick 如何将选项传递给 cwebp Linux
【发布时间】:2019-09-18 09:24:43
【问题描述】:

我在跑步

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian

我也在运行 ImageMagick 6.9。

我想将 PDF 图像转换为 WebP。 AFAIK,开箱即用,Linux 上的 ImageMagick 无法转换为 WebP,所以我 sudo apt-get install webp 安装了 cwebp

cwebp允许指定-q参数,ImageMagick允许指定-quality参数。

当我运行$ cwebp -q 90 image.png -o image.webp 时,cwebp 大约需要 8 秒才能转换它。如果我运行convert image.png -quality 90 image.webp,ImageMagick 需要大约 30 秒来转换它。似乎-quality 参数没有传递给cwebp。也可能是convert 尝试运行无损转换,这在cwebp 中是通过显式-lossless 标志实现的。

我为一个 10 MB 的测试 png 图像运行测试命令。

我想用convert 命令实现8 秒的转换时间。我该怎么做?

【问题讨论】:

标签: imagemagick imagemagick-convert converters webp


【解决方案1】:

我知道你想要 imagemagick,但如果你能够考虑替代方案,libvips 可以在命令行快速执行 pdf -> webp,无需任何配置。

例如,在我 2015 年的笔记本电脑上使用 this PDF (Audi R8 brochure),我看到:

$ time convert -density 600 r8.pdf[3] -quality 90 x.webp
real    0m36.699s
user    0m23.787s
sys 0m1.628s
$ vipsheader x.webp
x.webp: 9921x4961 uchar, 3 bands, srgb, webpload

我认为这与您所看到的时代大体一致。

使用 libvips,我明白了:

$ time vips copy r8.pdf[dpi=600,page=3] x.webp[Q=90]
real    0m7.195s
user    0m6.861s
sys 0m0.505s
$ vipsheader x.webp
x.webp: 9921x4961 uchar, 3 bands, srgb, webpload

同样的结果,但在您的 8 秒时间预算内。

如果您想更好地控制压缩,可以设置a lot of other webp options

【讨论】:

    【解决方案2】:

    事实证明,委托是使用/etc/ImageMagick-6/delegates.xml 中的规则调用的。

    它列出了一堆关于如何在不同类型的图像之间转换的规则。

    对于我的情况,png->webp 转换,我需要字符串: <delegate decode="png" encode="webp" command=""cwebp" -quiet %Q "%i" -o "%o""/>

    虽然在这个文件中我不知道-quaility 参数值,而且似乎没有办法捕获它。

    但是,如果您希望为cwebp 保留-q 参数的值,您可以选择将-q $YOUR_VALUE 硬编码到command 中的delegate 标记内。

    此解决方案仍然比直接调用 cwebp 慢,因为 ImageMagick 在调用委托之前最多可能需要 8 秒。

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多