【问题标题】:Optimize image with GraphicsMagick使用 GraphicsMagick 优化图像
【发布时间】:2015-07-11 09:06:48
【问题描述】:

我在 node.js 中使用 GraphicsMagick,我有很多(数千个)需要尽可能优化。每个都是 250*250 PX,我需要将它们设为 50*50,但这是简单的部分。

问题也在于如何优化它们。

通过优化它们,我的意思是把它们变成 jpeg 或 png(哪个更小)并降低质量(如果需要)和其他东西......

到目前为止我的代码...

gm(temp_location + file_name)
.gravity('Center')
.extent(50, 50)
.noProfile()
.write(new_location + "s"+name, function (err) {});

所以关于如何使图像更小有什么建议吗?
任何建议表示赞赏

【问题讨论】:

    标签: image-processing graphicsmagick


    【解决方案1】:

    对于 JPEG(最适合照片和其他自然图像),降低质量(即图像质量)会有所帮助。试试 -quality 40 或更少。

    对于 PNG(最适合线条艺术),将颜色限制为 254 或更少并提高质量(实际上意味着压缩级别)可能会有所帮助。对于颜色数量有限的 PNG,请使用 10 的偶数倍的“质量”,因为第二个数字指定 PNG 过滤方法,该方法应为“0”,表示不过滤。试试 -quality 90。

    【讨论】:

      【解决方案2】:

      对上述答案的补充,关于 GIF 格式优化。

      GraphicsMagick documentation 对 JPEG 或 PNG 压缩非常清楚,但是在输出 GIF 文件时(这是我的情况......),这些压缩功能似乎不适用。

      通过使用以下代码,我设法将 GIF 输出文件的大小减少了 52%:

      var gm = require('gm');
      gm()
      .in(input_filename1)
      .in(input_filename2)    
      .bitdepth(8)
      .colors(192)
      .dither(false)
      .filter('Point') // filter before resize to have a 'sharp big pixels' aspect
      .antialias(false)
      .resize(magnify_factor*size_x, magnify_factor*size_y, "!") 
      .write(output_filename, function (err) {
          if (!err) console.log('gif file created!');
      });
      

      这是我尝试过的其他功能,但在处理 GIF 时似乎没有效果

      .limit("disk", "500KB") 
      // this limits resource used but does not limit the output filesize
      
      .quality(10)
      
      .compress('LZW')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多