如何使用 Squoosh 命令行批量压缩图片

先说明:windows 上无法批量压缩,原因:

https://github.com/GoogleChromeLabs/squoosh/issues/973

因为 squoosh-cli 暂不支持 windows 上的通配符。这么一个小问题,给我整崩溃了。

完整过程如下

先在 (https://squoosh.app) 上测试一下图片压缩的设置:

image-20220922011515991

一切就绪后,点击右侧菜单 Edit 右边的控制台小图标,将命令复制下来,应该类似于这样:

npx @squoosh/cli --resize '{"enabled":true,"width":970,"height":970,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}'

如果想要先安装再使用,可以先用以下命令:

npm i -g @squoosh/cli

然后就可以用 squoosh-cli 命令了,将上面的命令改写一下:

squoosh-cli --resize '{"enabled":true,"width":970,"height":970,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}'

还有需要改动的地方就是:目标文件夹,目标文件,长宽

squoosh-cli --resize '{"enabled":true,"width":970,"height":970,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}' -d "[destinationfolder]" "*.png"

-d 参数后写上输出的文件夹,后面再跟需要压缩的图片,可以使用通配符(windows不行!),然后前面 --resize 的参数里长宽可以只保留一个参数,就不会压缩图片长宽比了:

squoosh-cli --resize '{"enabled":true,"width":500,"method":"lanczos3","fitMethod":"stretch","premultiply":true,"linearRGB":true}' --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"optimize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trellis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_subsample":2,"separate_chroma_quality":false,"chroma_quality":75}' -d "[destinationfolder]" "*.png"

然后就可以舒适地观看转换过程:

image-20220922012116526

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值