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

image-compressorionjs

v1.0.4

Published

A free and fast image compression tool

Readme

图片压缩

目录

开始

安装

npm install image-compressorionjs

使用

语法

new ImageCompressor(file[, options])

file

  • 类型: File or Blob

用于压缩的目标图像文件。

options

  • 类型: Object
  • 可选

压缩选项。查看可用选项

示例

<input type="file" id="file" accept="image/jpeg,image/jpg,image/png">
const ImageCompressor = require('image-compressorionjs');

document.getElementById('file').addEventListener('change', (ev) => {
  const file = ev.target.files[0];

  if (!(file && file.size > 0)) {
    return;
  }
  new ImageCompressor(file, {
      quality: 0.8,
      success(result){
        console.log('success:', result)
      },
      error(error){
        console.log('error:', error)
      }
  });
});

Options

您可以使用new ImageCompressor(file, options)设置压缩器选项。如果要更改全局默认选项,可以使用ImageCompressor.setDefaults(options)

width

  • 类型: number
  • 默认值: undefined

输出图像的宽度。如果未指定,将使用原始图像的自然宽度,或者如果设置了高度选项,则将根据自然纵横比自动计算宽度。

height

  • 类型: number
  • 默认值: undefined

输出图像的高度。如果未指定,将使用原始图像的自然高度,或者如果设置了宽度选项,则将根据自然纵横比自动计算高度。

quality

  • 类型: number
  • 默认值: 0.8

输出图像的质量。它必须是介于0和1之间的小数。如果此参数是其他值,则默认使用0.80。请小心使用,因为它可能会使输出图像的大小变大。

**注意:**此选项仅适用于“image/jpeg”图像。

mimeType

  • 类型: string
  • 默认值: 'image/jpeg'
  • 选项: "image/jpeg", "image/png", and "image/jpg".

输出图像的文件类型。默认情况下,它将被转换为“image/jpeg”文件类型。

maxConversionSize

  • 类型: number
  • 默认值: undefined

输出图像的最高质量。配置此属性时,设置的“quality”属性将不再有效。

orientation

  • 类型: boolean
  • 默认值: false

是否自动矫正图片。仅支持jpg、jpeg图像类型。此配置同旋转角度rotate属性互斥,同时设置的情况下会优先使用自动矫正

sizeThreshold

  • 类型: number
  • 默认值: undefined

设置压缩阈值,即文件大小大于设置的值时才执行压缩操作,默认单位是KB。可以同strictSizeThreshold组合使用

strictSizeThreshold

  • 类型: boolean
  • 默认值: true

当不满足设置的压缩条件(sizeThreshold)时,是否直接输出原图的处理结果(默认是true) 设置为true时,表示当不处于压缩条件(小于sizeThreshold)时,只会做一个返回结果类型(responseType)的处理; 设置为false时,表示当不处于压缩条件(小于sizeThreshold)时,除了压缩质量quality和最大质量maxConversionSize配置项不生效以外,其他都会生效,同时默认输出的mimeType调整为原始文件类型

rotate

  • 类型: number
  • 默认值: undefined

图片旋转角度输出。此配置同自动转正orientation属性互斥,同时设置的情况下会优先使用自动矫正

responseType

  • 类型: string
  • 默认值: 'file'
  • 选项: "file", "blob", "base64", and "arraybuffer".

图像压缩后返回的结果类型。默认情况下,返回压缩图像的“file”对象

success(result)

  • 类型: Function
  • 默认值: null
  • 参数:
    • result: 压缩成功的结果.

error(error)

  • 类型: Function
  • 默认值: null
  • 参数:
    • error: 压缩失败的对象.

方法

  • 暂无

浏览器支持

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Opera (latest)
  • Edge (latest)
  • Internet Explorer 10+