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

au_tinypng

v2.0.1

Published

Tinypng without "Too many files uploaded at once" limit

Readme

au_tinypng

基于 TinyPNG Web 接口的本地图片压缩工具。进入图片目录后执行命令,它会递归扫描当前目录下的图片,压缩成功后直接替换原图,并记录处理状态,方便失败后重复执行。

功能

  • 递归处理当前执行目录下的子目录图片。
  • 支持 .jpg.jpeg.png.gif
  • 单张图片最大支持约 5MB,超过会跳过并记录原因。
  • 压缩成功后直接覆盖原图片,不再生成额外输出目录。
  • 通过 hash 记录压缩前后的文件状态,重复执行时会跳过已压缩成功的图片。
  • 压缩失败的图片会记录失败次数,下次执行继续重试。
  • 同一张图片同一 hash 连续失败达到上限后会自动跳过,避免一直重复失败。
  • 命令行会展示进度条、当前进度、压缩后占比和节省比例。

安装

npm i au_tinypng -g

使用

进入需要压缩图片的目录后执行:

au_tinypng

指定每张图片之间的压缩间隔,默认 2000 毫秒:

au_tinypng --delay 3000

指定同一张图片连续失败的最大重试次数,默认 3 次:

au_tinypng --max-retries 5

参数可以组合使用:

au_tinypng --delay 3000 --max-retries 5

处理规则

执行命令时,工具会以当前目录为根目录递归查找图片。

压缩成功后,压缩后的图片会直接写回原文件路径。例如:

images/banner.png

压缩完成后仍然是:

images/banner.png

工具会在当前执行目录生成缓存文件:

.au_tinypng-compress-cache.json

缓存文件会记录每张图片的相对路径、压缩前 hash、压缩后 hash、压缩结果、失败次数和最后更新时间。

再次执行时:

  • 如果当前图片 hash 等于缓存中的压缩后 hash,说明已经压缩成功,会直接跳过。
  • 如果图片上次失败但还没达到失败上限,会继续尝试压缩。
  • 如果同一张图片同一 hash 已连续失败达到上限,会跳过,避免死循环。
  • 如果图片内容被修改,hash 会变化,工具会把它当作新的待处理图片重新压缩。

输出示例

压缩中:

[######------------------] 1/4 25.00% 压缩中:images/组 3@2x_副本.png

压缩成功:

[完成] images/组 3@2x_副本.png | 364 KB -> 73.1 KB | 压缩后 20.08% | 节省 79.92%

压缩失败:

[失败] images/demo.png | Request is invalid

跳过已压缩图片:

[images/banner.png] 已压缩成功,跳过。

达到失败上限:

[images/error.png] 已连续失败 3 次,跳过。可修改图片后重试,或使用 --max-retries 提高上限。

注意事项

  • 压缩成功会直接替换原图,建议在 Git 工作区或已有备份的目录中使用。
  • 当前脚本本质上调用 TinyPNG 的 Web 接口,请合理使用。
  • 图片过大、格式异常、接口限制或网络问题都可能导致压缩失败。
  • 如果某张图片一直失败,可以手动处理该图片,或者调整 --max-retries 后再次执行。
  • 如果想让某张已压缩图片重新参与压缩,可以修改图片内容,或谨慎删除 .au_tinypng-compress-cache.json 中对应记录。

免责声明

该工具仅用于学习和提升本地图片处理效率。如有商业用途,请购买 TinyPNG 官方服务。

作者:龍