我正在尝试使用Graphics::Magick在Perl中将PNG文件转换为无损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“呢?
谢谢,
更新:看起来我需要调用AddDefiniton接口函数(http://www.graphicsmagick.org/api/image.html#adddefinition)。到目前为止,它看起来还没有通过Perl API导出。
发布于 2019-05-27 21:17:12
我知道它对您没有任何帮助,但对于那些对如何在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选项,请查看this code
https://stackoverflow.com/questions/47294962
复制相似问题