【问题标题】:Nodejs Sharp webp lossless compressionNodejs Sharp webp无损压缩
【发布时间】:2019-07-24 00:31:18
【问题描述】:

我正在开发类似的 Imgix 服务,我正在使用 Sharp。

但是 webp 无损压缩 Imgix 得到的效果比 Sharp 好。在 Imgix 中具有相同宽度和高度的相同图像有 453 KB 和 Sharp 1.3 MB。

在不损失质量的情况下增加压缩率的一些建议?

我正在使用的代码:

https.get(url, function (response) {
    let transform = sharp().toFormat('webp').resize(width, height);
    return response.pipe(transform).webp({lossless:true}).pipe(res);
});

【问题讨论】:

标签: node.js sharp


【解决方案1】:

关于如何使用 Sharp 的 webp output options 的文档不存在 AFAICT,但根据此 comment 选项 nearLosslessquality 应该一起使用,而 lossless:true 选项等效于 @987654326 @

根据我的经验,nearLossless:true,quality:50 会将文件大小减少到不到lossless:true 的一半,同时保留大部分质量。

【讨论】:

    【解决方案2】:

    我看到document 在选项中有一些文件:质量、alphaQuality、nearLossless、force。你能试试吗?并与 IMGIX 比较

    • 质量:数字质量,1-100整数(可选,默认80)
    • alphaQuality:alpha层的数字质量,整数0-100(可选,默认100)
    • 无损:布尔使用无损压缩模式(可选,默认false)
    • nearLossless:布尔使用near_lossless压缩模式(可选,默认false)
    • force:Boolean 强制 WebP 输出,否则尝试使用输入格式(可选,默认 true)
    https.get(url, function (response) {
        let transform = sharp().toFormat('webp').resize(width, height);
        return response.pipe(transform).webp({lossless:true, quality: 60, alphaQuality: 80, force: false}).pipe(res);
    });
    

    【讨论】:

      猜你喜欢
      • 2014-05-18
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2015-01-31
      • 2011-02-07
      • 2019-02-14
      • 1970-01-01
      相关资源
      最近更新 更多