Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lemonnekogh/crop-empty-pixels
https://github.com/lemonnekogh/crop-empty-pixels
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/lemonnekogh/crop-empty-pixels
- Owner: LemonNekoGH
- License: mit
- Created: 2023-07-18T18:10:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-20T11:49:33.000Z (over 1 year ago)
- Last Synced: 2024-10-26T22:53:01.223Z (about 2 months ago)
- Language: TypeScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crop empty pixels
This package is **ONLY** for browsers## Usage
```js
import cropImg from 'crop-empty-pixels'// load a image
const img = document.createElement('img')
img.src = '/path/to/an/image/with/empty/border'
img.addEventListener('load', () => {
// draw it on canvas once load
const canvas = document.createElement('canvas')
const canvasCtx = canvas.getContext('2d')!
canvasCtx.drawImage(img)
// pass the canvas to function then get new canvas
const cropped = cropImg(canvas)
// set cropped image data to origin
img.src = cropped.toDataURL()
}, { once: true })
```