- Notifications
You must be signed in to change notification settings - Fork1
Unified method of retrieving an ImageData instance from an image, in both the browser and Node.js, asynchronously or synchronously
License
andreekeberg/imagedata
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Unified method of retrieving anImageData instance from an image, in both thebrowser andNode.js, asynchronously or synchronously. Also exports anImageData polyfill inNode.js, allowing you to type check instances in both environments.
AnImageData object always contains the following properties:
dataUint8ClampedArray representing a one-dimensional array containing the data in the RGBA order, with integer values between 0 and 255 (inclusive).
widthUnsigned long representing the actual width, in pixels, of the ImageData.
heightUnsigned long representing the actual height, in pixels, of the ImageData.
- jpeg
- png
- gif
- bmp
- tiff
npm install @andreekeberg/imagedatayarn add @andreekeberg/imagedataimport{get,getSync}from'@andreekeberg/imagedata'
const{ get, getSync}=require('@andreekeberg/imagedata')
| Type | Description |
|---|---|
string | Path to image file |
HTMLImageElement | Reference to an<img> element |
File | Generally returned from an<input> element |
Blob | Raw binary data blob |
get('image.jpg',(error,data)=>{if(error){console.log(error)}else{console.log(data)}})
| Type | Description |
|---|---|
HTMLImageElement | Reference to an<img> element |
Throws an
Errorif the provided image has not completed loading
constimage=document.querySelector('img')try{console.log(getSync(image))}catch(error){console.log(error)}
| Type | Description |
|---|---|
string | Path to image file |
Buffer | Created fromfs.readFile orfs.readFileSync |
fs.ReadStream | Created fromfs.createReadStream |
get('image.jpg',(error,data)=>{if(error){console.log(error)}else{console.log(data)}})
| Type | Description |
|---|---|
string | Path to image file |
Buffer | Created fromfs.readFile orfs.readFileSync |
try{console.log(getSync('image.jpg'))}catch(error){console.log(error)}
Read thecontribution guidelines.
Refer to thechangelog for a full history of the project.
ImageData is licensed under theMIT license.
About
Unified method of retrieving an ImageData instance from an image, in both the browser and Node.js, asynchronously or synchronously
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.