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 🙏

© 2025 – Pkg Stats / Ryan Hefner

minify-pic-cli

v1.1.0

Published

一个简单易用的图片批量压缩命令行工具,支持 PNG、JPEG、GIF 格式,适合前端和设计师快速优化图片体积。

Readme

Minify Pic CLI - 图片批量压缩工具

简体中文 | English

一个简单易用的图片批量压缩命令行工具,支持 PNG、JPEG、GIF 格式,适合前端和设计师快速优化图片体积。

功能特性

  • 🖼️ 支持多种图片格式:PNG、JPEG、GIF
  • 📁 批量处理目录及子目录中的所有图片
  • ⚙️ 可自定义压缩质量和参数
  • 🚫 支持排除指定目录
  • 📊 显示压缩前后文件大小对比
  • 🎯 保持原有目录结构
  • ⚡ 支持跳过确认,自动化执行
  • 🔄 支持原地压缩替换原文件

安装

全局安装

# 使用 pnpm 安装
pnpm install -g minify-pic-cli

# 或使用 npm
npm install -g minify-pic-cli

使用方法

基本用法

# 压缩当前目录的所有图片
mpic

# 或直接运行
node index.js

命令行选项

mpic [选项]

选项:
  -d, --dir <dir>              需要压缩的目录 (默认: 当前目录)
  -o, --output <output>        输出目录 (默认: ./output)
  -q, --quality <quality>      压缩质量 0-100 (默认: 80)
  -g, --gif-colours <colours>  GIF调色板最大数量 2-256 (默认: 128)
  -b, --black-dirs <dirs>      排除的子文件夹名称,逗号分隔 (默认: "no")
  -y, --yes                    跳过确认,直接开始压缩
  -r, --replace                原地压缩替换原文件,不输出到新目录
  -v, --version                显示版本号
  -h, --help                   显示帮助信息

使用示例

# 压缩指定目录的图片,输出到 compressed 文件夹
mpic -d ./images -o ./compressed

# 设置压缩质量为 90
mpic -q 90

# 排除 node_modules 和 .git 目录
mpic -b "node_modules,.git"

# 设置 GIF 调色板为 64 色
mpic -g 64

# 跳过确认提示,自动开始压缩
mpic -y

# 原地压缩替换原文件(不创建新目录)
mpic -r

# 跳过确认 + 原地替换(自动化场景推荐)
mpic -y -r

# 原地替换 + 自定义压缩质量
mpic -y -r -q 90

# 组合使用多个选项
mpic -d ./src/assets -o ./dist/assets -q 85 -b "node_modules,.git"

支持的图片格式

  • PNG: 支持透明度,适合图标和简单图形
  • JPEG: 适合照片和复杂图像
  • GIF: 支持动画,可调整调色板颜色数量

配置说明

压缩质量 (quality)

  • 范围:0-100
  • 默认:80
  • 数值越高,质量越好,文件越大
  • 建议:80-90 为最佳平衡点

GIF 调色板颜色数 (gif-colours)

  • 范围:2-256
  • 默认:128
  • 颜色数越少,文件越小,但可能影响视觉效果
  • 建议:64-128 为常用范围

排除目录 (black-dirs)

  • 支持多个目录,用逗号分隔
  • 默认排除 "no" 目录
  • 常用排除目录:node_modules,.git,dist,build

输出说明

工具会在控制台显示:

  • 当前工作目录
  • 压缩进度和结果
  • 文件大小变化对比
  • 最终输出目录

示例输出:

当前目录路径为: /path/to/your/project
是否需要压缩当前目录的所有图片?Y/N:y
压缩完成 [大小变化: 2.5MB ---->>>> 1.2MB] /path/to/output/image1.jpg
压缩完成 [大小变化: 800KB ---->>>> 400KB] /path/to/output/image2.png
压缩任务全部完成,已输出至 /path/to/output

注意事项

  1. 备份原文件:默认模式会创建新的压缩文件到输出目录,不会覆盖原文件
  2. 原地替换模式:使用 -r 参数会直接替换原文件,请谨慎使用,建议先备份重要文件
  3. 输出目录:默认输出到 ./output 目录,会自动创建(使用 -r 时不会创建)
  4. 目录结构:压缩后会保持原有的目录结构
  5. 大文件处理:对于大文件,压缩可能需要一些时间
  6. 权限问题:确保对目标目录有写入权限
  7. 自动化脚本:在 CI/CD 或自动化脚本中,建议使用 -y 参数跳过交互确认

技术栈

  • Node.js: 运行环境
  • Sharp: 高性能图片处理库
  • Commander.js: 命令行参数解析
  • Readline: 用户交互

开发

# 安装依赖
pnpm install

# 运行开发版本
node index.js

许可证

ISC

更新日志

v1.0.3

  • 新增 -y, --yes 参数:跳过确认提示,支持自动化执行
  • 新增 -r, --replace 参数:原地压缩替换原文件
  • 优化用户体验,提供更多灵活的使用方式

v1.0.2

  • 初始版本发布
  • 支持 PNG、JPEG、GIF 格式压缩
  • 命令行参数支持
  • 批量处理功能