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

@aurouscia/image-compress

v0.0.0

Published

基于 canvas 的客户端图片压缩与缩放工具,支持 object-fit 风格的配置

Readme

@aurouscia/image-compress

客户端图片压缩与缩放工具,支持 Canvas 绘制、object-fit 模式及自定义输出格式。

功能

  • compressImage:将图片绘制到指定尺寸的 Canvas 上,支持 CSS object-fit 风格的填充模式(contain、cover、fill、none、scale-down)。
  • resizeImage:按最大宽高等比缩放图片,画布尺寸等于缩放后的图片尺寸,不会放大。
  • 输出格式与质量可调,默认输出 image/webp

安装

npm install @aurouscia/image-compress

使用

compressImage

将图片压缩到固定画布尺寸,使用 objectFit 控制绘制方式:

import { compressImage } from '@aurouscia/image-compress'

const { blob, canvas } = await compressImage(file, {
  width: 300,
  height: 300,
  objectFit: 'contain',
  type: 'image/webp',
  quality: 0.8,
})

resizeImage

按最大尺寸限制等比缩放,不超出限制也不放大:

import { resizeImage } from '@aurouscia/image-compress'

const { blob, canvas } = await resizeImage(file, {
  maxWidth: 1920,
  maxHeight: 1080,
  type: 'image/jpeg',
  quality: 0.9,
})

选项说明

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | width | number | 原图宽度 | compressImage 专用,画布宽度 | | height | number | 原图高度 | compressImage 专用,画布高度 | | objectFit | ObjectFit | 'contain' | compressImage 专用,绘制模式 | | maxWidth | number | 无限制 | resizeImage 专用,最大宽度 | | maxHeight | number | 无限制 | resizeImage 专用,最大高度 | | type | string | 'image/webp' | 输出 MIME 类型 | | quality | number | 0.8 | 输出质量(0 ~ 1) |

开发

# 安装依赖
pnpm install

# 构建库
pnpm run build

# 运行演示项目
pnpm run dev

# 运行测试
pnpm run test:run

License

MIT