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

aardpro-crop-image

v1.2.0

Published

Before uploading an image file or dataURL, crop and optimize it to the specified size and quality.在上传图片文件或者dataURL编码前,对它进行剪裁和优化到指定的尺寸和质量。

Downloads

18

Readme

aadpro-crop-image

注意 Note

  • 仅支持在浏览器环境使用,不支持nodejs环境
  • available only in browser environment only, unavailable in nodejs environment

安装 Installation

pnpm

pnpm i aadpro-crop-image

npm

npm i aadpro-crop-image

yarn

yarn add aadpro-crop-image

使用说明 - 中文 | Usage - english

cropFile

剪裁文件并返回文件对象

 import { cropFile  } from 'aadpro-crop-image'

 // sourceFile是从<input type="file" accept="image/*">获取到的文件
 const { dataURL, file }  = await cropFile({
   file: sourceFile,
   width: 300,
   height: 300,
   quality: 0.8,
   origin: 'center'
 })

cropDataURL

剪裁dataURL字符串并返回dataURL字符串

 import { cropDataURL  } from 'aadpro-crop-image'

 // sourceDataURL是base64字符串, 比如: 'data:image/png;base64,xxx' 
 const { dataURL, file } = await cropDataURL({
   dataURL: sourceDataURL,
   width: 300,
   height: 300,
   quality: 0.8,
   origin: 'center'
 })

fileToDataURL

将文件转为dataURL字符串

 import { fileToDataURL  } from 'aadpro-crop-image'

 const dataURl = await fileToDataURL(file)

dataURLToFile

将dataURL字符串转为文件

 import { dataURLToFile  } from 'aadpro-crop-image'

 const file = await dataURLToFile(dataURL)

参数

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ------- | ---- | ------ | ------ | ----------------------------- | | file | 是 | File | | 上传的文件 | | dataURL | 是 | string | | 上传的dataURL字符串 | | width | 否 | number | 300 | 剪裁的宽度;0表示不剪裁 | | height | 否 | number | 300 | 剪裁的高度;0表示不剪裁 | | quality | 否 | number | 0.75 | 压缩质量 0-1 | | origin | 否 | string | center | 初始位置 |

origin可用值

| Origin | Description | | ------------ | ------------ | | center | 从中心剪裁 | | top-left | 从左上角剪裁 | | top-right | 从右上角剪裁 | | bottom-left | 从左下角剪裁 | | bottom-right | 从右下角剪裁 |

Usage - english

cropFile

Crop a file and return a File object

 import { cropFile  } from 'aadpro-crop-image'

 // sourceFile is an File object  from <input type="file" accept="image/*">
 const { dataURL, file } = await cropFile({
   file: sourceFile,
   width: 300,
   height: 300,
   quality: 0.8,
   origin: 'center'
 })

cropDataURL

Crop a dataURL string and return a dataURL string

 import { cropDataURL  } from 'aadpro-crop-image'

 // sourceDataURL is base64 dataURL string, eg: 'data:image/png;base64,xxx' 
 const { dataURL, file } = await cropDataURL({
   dataURL: sourceDataURL,
   width: 300,
   height: 300,
   quality: 0.8,
   origin: 'center'
 })

fileToDataURL

Convert a file to a dataURL string

 import { fileToDataURL  } from 'aadpro-crop-image'

 const dataURl = await fileToDataURL(file)

dataURLToFile

Convert a dataURL string to a file

 import { dataURLToFile  } from 'aadpro-crop-image'

 const file = await dataURLToFile(dataURL)

Options

| parameter | required | type | default | description | | --------- | -------- | ------ | ------- | ------------------------------------- | | file | yes | File | | | | dataURL | yes | string | | | | width | no | number | 300 | target width;0 means no crop | | height | no | number | 300 | target height;0 means no crop | | quality | no | number | 0.75 | 0-1 | | origin | no | string | center | origin positions |

origin values

| Origin | Description | | ------------ | --------------------------------- | | center | Crop from the center | | top-left | Crop from the top-left corner | | top-right | Crop from the top-right corner | | bottom-left | Crop from the bottom-left corner | | bottom-right | Crop from the bottom-right corner |