@frostoven/squoosh-cli

中文文档
0.9.1发布于 2024/04/30Apache-2.0ES Module近 30 天下载 2594

A CLI for Squoosh

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Auto optimizer

Squoosh CLI

Squoosh CLI is an experimental way to run all the codecs you know from the Squoosh web app on your command line using WebAssembly. The Squoosh CLI uses a worker pool to parallelize processing images. This way you can apply the same codec to many images at once.

Squoosh CLI is currently not the fastest image compression tool in town and doesn't aim to be. It is, however, fast enough to compress many images sufficiently quick at once.

Please note that this is a fork of the original library, which has since been retired. This fork continues that work and has some bugs fixes.

Installation

The Squoosh CLI can be used straight from the command line without installing using npx:

$ npx @frostoven/squoosh-cli <options...>

Of course, you can also install the Squoosh CLI:

$ npm i -g @frostoven/squoosh-cli
$ squoosh-cli <options...>

Usage

Usage: squoosh-cli [options] <files...>

Options:
  -d, --output-dir <dir>                                 Output directory (default: ".")
  -s, --suffix <suffix>                                  Append suffix to output files (default: "")
  -c, --max-concurrent-files <count>                     Amount of files to process at once (defaults to your CPU core count)
  --max-optimizer-rounds <rounds>                        Maximum number of compressions to use for auto optimizations (default: "6")
  --optimizer-butteraugli-target <butteraugli distance>  Target Butteraugli distance for auto optimizer (default: "1.4")
  --resize [config]                                      Resize the image before compressing
  --quant [config]                                       Reduce the number of colors used (aka. paletting)
  --rotate [config]                                      Rotate image
  --mozjpeg [config]                                     Use MozJPEG to generate a .jpg file with the given configuration
  --webp [config]                                        Use WebP to generate a .webp file with the given configuration
  --avif [config]                                        Use AVIF to generate a .avif file with the given configuration
  --jxl [config]                                         Use JPEG-XL to generate a .jxl file with the given configuration
  --wp2 [config]                                         Use WebP2 to generate a .wp2 file with the given configuration
  --oxipng [config]                                      Use OxiPNG to generate a .png file with the given configuration
  -V, --version                                          Output associated version numbers
  -h, --help                                             Display help for command

The default values for each config option can be found in the codecs.ts file under defaultEncoderOptions. Every unspecified value will use the default value specified here. Better documentation is needed here.

Auto optimizer

Squoosh CLI has an experimental auto optimizer that compresses an image as much as possible, trying to hit a specific Butteraugli target value. The higher the Butteraugli target value, the more artifacts can be introduced.

You can make use of the auto optimizer by using “auto” as the config object.

$ npx @frostoven/squoosh-cli --wp2 auto test.png

版本与发布记录

@frostoven/squoosh-cli 共发布 6 个版本,首次发布于 2023/05/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.1latest2024/04/302 年前
0.9.02024/04/302 年前
0.8.12024/04/292 年前
0.7.62023/09/273 年前
0.7.52023/05/203 年前
0.7.42023/05/203 年前

关于 @frostoven/squoosh-cli 的常见问题

@frostoven/squoosh-cli 是什么?

A CLI for Squoosh

如何安装 @frostoven/squoosh-cli?

在项目目录运行 npm install @frostoven/squoosh-cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 squoosh-cli、squoosh-cli-debug,可以用 npx squoosh-cli 直接运行。

@frostoven/squoosh-cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/frostoven__squoosh-cli 是否存在。

@frostoven/squoosh-cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@frostoven/squoosh-cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@frostoven/squoosh-cli 可以商用吗?

@frostoven/squoosh-cli 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@frostoven/squoosh-cli 的下载量有多少?

根据 npm 官方下载统计,@frostoven/squoosh-cli 在 2026/10/16 – 2026/11/14 这 30 天内被下载 2,594 次,日均约 86 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frostoven/squoosh-cli 还在维护吗?

最新版本 0.9.1 发布于 2024/04/30(2 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/05/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。