npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wolf-cimg

v0.0.3

Published

Batch image compression to WebP — single file or folder

Readme

cimg

批量将图片压缩为 WebP,支持单文件或整个文件夹(可选递归子目录)。适合团队统一压缩图片、减小体积。

安装

任选一种方式即可使用:

方式一:像正常脚本一样用(推荐)

装好依赖后,用 npx 跑(须在项目目录内,或把项目路径写给 npx):

cd C:\Users\sami\Documents\sg\compress-img   # 先进入项目目录
npm install
npx cimg <路径> [选项]
# 例如
npx cimg C:\Users\sami\Desktop\spinner.webp -s 100

若不想先 cd,可直接用项目路径:
npx C:\Users\sami\Documents\sg\compress-img C:\Users\sami\Desktop\spinner.webp -s 100

用法

cimg [input] [options]

| 选项 | 简写 | 说明 | | ------------------- | ---- | --------------------------------------------------------------------- | | --out-dir <dir> | -o | 输出目录;不指定则直接修改源文件(同目录生成 .webp 后删除原文件) | | --size <px> | -s | 最大边长(可选;不指定则只压缩不缩放) | | --quality <1-100> | -q | WebP 质量,默认 75 | | --no-webp | | 不转为 WebP,保留原格式仅压缩(默认转为 WebP) | | --recursive | -r | 递归处理子目录 | | --help | -h | 显示帮助 | | --version | -V | 显示版本 |

示例

以下示例用 cimgnpx cimg 均可(全局安装用前者,项目内用后者):

# 压缩当前目录下所有图片并直接替换源文件(生成 .webp 后删除原图)
cimg .

# 压缩指定目录,并限制最大边长为 1200px
cimg ./photos --size 1200

# 压缩单张图片,并指定输出目录
cimg ./photo.png --out-dir ./out

# 递归压缩文件夹及子文件夹内所有图片,质量 80
cimg ./assets -r -q 80

# 项目内不全局安装时
npx cimg ./img -o ./dist -s 800

若一定要用 npm run compress,须在参数前加 --,否则 --size 等会被 npm 截掉:
npm run compress -- ./photo.png --size 100

支持格式

  • jpg / jpeg
  • png
  • webp
  • gif(含动图)

默认输出为 WebP;加 --no-webp 时保留原格式(jpg/png/gif 等)仅做压缩。

环境要求

  • Node.js >= 18

发布到 npm(维护者)

发布后,任何人可在任意目录执行 npx cimg ...,无需进入项目。

  1. 注册 npm 账号(若没有):打开 npmjs.com 注册。

  2. 登录:在项目根目录执行
    npm login,按提示输入用户名、密码和邮箱。

  3. 检查包名:npm 上若已有他人占用 cimg,需改用作用域包名,例如在 package.json 里把 "name": "cimg" 改为 "name": "@你的用户名/cimg"。发布后用户执行:npx @你的用户名/cimg ...

  4. 发布

    cd C:\Users\sami\Documents\sg\compress-img
    npm publish

    若使用作用域包名且首次发布,需执行:npm publish --access public

  5. 之后更新:改好代码后,执行 npm version patch(或 minor / major)再执行 npm publish

不登录 npm 的用法(内网 / 团队)

不把包发到 npmjs.com,也能让团队直接用,无需 npm 账号。

方式 A:推代码到 Git,用 npx 从仓库跑(推荐)

把项目推到 GitHub / GitLab / 内网 Git 后,任何人执行(无需登录 npm):

# GitHub 示例(把 your-org/cimg 换成你的仓库)
npx git+https://github.com/your-org/cimg.git ./photo.png -s 100
# 或
npx github:your-org/cimg ./photo.png -s 100

每次执行会拉取最新代码再跑,适合经常更新。

方式 B:从 Git 全局安装一次

npm install -g git+https://github.com/your-org/cimg.git
# 之后在任意目录
cimg ./photo.png -s 100

方式 C:内网私有 npm(如 Verdaccio)

在公司内网搭一个私有 npm registry(如 Verdaccio),在本机把 registry 指过去后照常 npm publish,团队用该 registry 安装,不经过 npmjs.com,也不需登录公网 npm。

常见问题

  • Windows 路径:可使用 .\photosC:\path\to\folder,脚本会按绝对路径处理。
  • 权限:若输出目录无写权限,会报错;请确保对目标目录有写入权限。