autocrop-js

0.2.0 • Public • Published

autocrop-js

Illustration of how autocrop-js works (Used image from https://pixabay.com/illustrations/ai-generated-generative-ai-fantasy-7700016/)

Node.js utility that crops the transparent background of an image.

Installation

npm install autocrop-js

Usage

import autocrop from 'autocrop-js'

const dataURL = 'data:image/png;base64,...'

autocrop(dataURL, {
  alphaThreshold: 10 // the lines and columns will be removed if the alpha channel is below the specified value (0-255). Default: 0
}).then(result => {
  console.log(result)
})

Output:

{
  bbox: { // bounding box of the cut image fragment
    height: 188,
    width: 232,
    x: 26,
    y: 0
  },
  dataURL: 'data:image/png;base64,iVB...' // Data URL of the cut image fragment
}

Testing

npm test

Linting

npm run lint

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT

Package Sidebar

Install

npm i autocrop-js

Weekly Downloads

6

Version

0.2.0

License

MIT

Unpacked Size

954 kB

Total Files

26

Last publish

Collaborators

  • arhey