1

我正在尝试使用 Graphics::Magick 将 PNG 文件转换为 Perl 中的无损 WebP。命令行是:

$ gm convert in.png -define webp:lossless=true out.webp

我的 Perl 代码看起来像这样:

use Graphics::Magick;

my $image = Graphics::Magick->new();
$image->Read("in.png");
my $image_data = $image->ImageToBlock(magick => "webp");
print $out_fh $image_data;

这段代码完美地编写了有损 WebP 文件,但是我如何用 Perl API 来表达“-define”的东西呢?

谢谢,

更新:看起来我需要调用AddDefinitonAPI 函数(http://www.graphicsmagick.org/api/image.html#adddefinition)。看起来它现在还没有通过 Perl API 导出。

4

1 回答 1

0

我知道这对您没有帮助,但是对于那些对如何在 PHP 中执行此操作感兴趣的人,以下是方法:

$im = new \Gmagick($src);
$im->setimageformat('WEBP');

// Not completely sure if setimageoption() has always been there, so lets check first.
if (method_exists($im, 'setimageoption')) {
    $im->setimageoption('webp', 'lossless', 'true');
}
$imageBlob = $im->getImageBlob();
$success = @file_put_contents($destination, $imageBlob);

有关更多 webp 选项,请查看此代码

于 2019-05-27T13:17:11.683 回答