crop-image-data
v1.0.4
Published
Function for cropping an image through its ImageData.
Downloads
1,724
Maintainers
Readme
crop-image-data
✂️ Function for cropping an image through its ImageData.
Demo
https://crop-image-data.netlify.app
Installation
# npm
npm install crop-image-data
# pnpm
pnpm install crop-image-data
# yarn
yarn add crop-image-data
Usage
cropImageData(imageData, cropOptions)
Creates a cropped version of an ImageData-instance. Does not mutate the recieved instance.
Parameters:
imageData
- the ImageData-instance instance to cropcropOptions
- an object specifying the amount of pixels to crop from each sidetop
- number of pixels to crop from the topright
- number of pixels to crop from the right sidebottom
- number of pixels to crop from the bottomleft
- number of pixels to crop from the left side
Return value:
A new, cropped ImageData-instance.
Examples:
import cropImageData from 'crop-image-data';
// crop 5 pixels on every side
const cropped = cropImageData(imageData, { top: 5, right: 5, bottom: 5, left: 5 });
// crop 50 pixels from the top
const croppedTop = cropImageData(imageData, { top: 50 });
// crop 10 pixels on each side
const croppedSides = cropImageData(imageData, { left: 10, right: 10 });
Related packages
- trim-image-data - finds and trims whitespace (or a specified color) from an image using
crop-image-data