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

pic-compressor

v0.1.3

Published

🦅 Zero-dependency browser image compressor with presets, target-size iteration, long-image support, and batch processing.

Readme

pic-compressor

CI npm version Coverage License Node.js

独立的浏览器图片压缩工具,基于 Canvas,零运行时依赖,支持普通图片、长截图、全景图、Blob、FileList、目标体积迭代和取消操作。

安装

npm install pic-compressor

使用

import { compressImage } from 'pic-compressor';

const result = await compressImage(file, {
  preset: 'balanced',
  outputMode: 'compact'
});

console.log(result.file, result.width, result.height, result.afterKB);

预设包括 balanced、social、high-quality、thumbnail 和 long-image。显式参数优先于预设。默认 balanced 目标为最大 1920px、约 500KB,长图会保留合理长边并受像素和 Canvas 上限约束。

指定目标体积时,压缩器会先搜索最高可接受质量,必要时再按比例缩小尺寸:

const result = await compressImage(file, {
  mime: 'image/webp',
  targetFileSizeKB: 300,
  outputMode: 'compact',
  onProgress: (progress) => console.log(`${progress}%`)
});

输入可以是 File、Blob 或 FileList。Blob 可通过 fileName 指定输出文件名。默认保留旧版 Data URL 和二进制字段;在生产环境推荐 outputMode: 'compact' 降低内存峰值。

格式转换允许体积变大,例如 JPEG 转 PNG。对于同格式输出,keepOriginalIfLarger 默认为 true;若业务需要保留更大的重编码结果,可设置为 false。

浏览器 CDN

<script src="https://unpkg.com/pic-compressor/dist/index.umd.js"></script>
<script>
  const result = await PicCompressor.compressImage(file, { outputMode: 'compact' });
</script>

开发

npm install
npm run verify
npm run build

构建输出:

  • dist/index.mjs:ESM
  • dist/index.cjs:CommonJS
  • dist/index.d.mts / dist/index.d.cts:TypeScript 声明
  • dist/index.umd.js:压缩后的 UMD 浏览器包及 Source Map

ESM、CommonJS、UMD 和类型声明均由 tsdown 生成,Lint 和格式化由 Oxc 的 oxlint/oxfmt 完成。

API

完整参数和返回值见 docs/api.md。

社区与贡献

兼容性

目标环境需要 File、Blob、FileReader、Canvas 2D 和图片解码 API。原生 iOS、Android、React Native 文件 URI 需要先转换为 Web File,或使用原生图片 API。

License

MIT