Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unified method of retrieving an ImageData instance from an image, in both the browser and Node.js, asynchronously or synchronously

License

NotificationsYou must be signed in to change notification settings

andreekeberg/imagedata

Repository files navigation

VersionTotal DownloadsLicense

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:

data

Uint8ClampedArray representing a one-dimensional array containing the data in the RGBA order, with integer values between 0 and 255 (inclusive).

width

Unsigned long representing the actual width, in pixels, of the ImageData.

height

Unsigned long representing the actual height, in pixels, of the ImageData.

Supported formats

  • jpeg
  • png
  • gif
  • bmp
  • tiff

Installation

Using npm

npm install @andreekeberg/imagedata

Using yarn

yarn add @andreekeberg/imagedata

Getting started

Import as an ES6 module

import{get,getSync}from'@andreekeberg/imagedata'

Import as a CommonJS module

const{ get, getSync}=require('@andreekeberg/imagedata')

Usage (Browser)

Asynchronously

Available input types

TypeDescription
stringPath to image file
HTMLImageElementReference to an<img> element
FileGenerally returned from an<input> element
BlobRaw binary data blob

Example

get('image.jpg',(error,data)=>{if(error){console.log(error)}else{console.log(data)}})

Synchronously

Available input types

TypeDescription
HTMLImageElementReference to an<img> element

Throws anError if the provided image has not completed loading

Example

constimage=document.querySelector('img')try{console.log(getSync(image))}catch(error){console.log(error)}

Usage (Node.js)

Asynchronously

Available input types

TypeDescription
stringPath to image file
BufferCreated fromfs.readFile orfs.readFileSync
fs.ReadStreamCreated fromfs.createReadStream

Example

get('image.jpg',(error,data)=>{if(error){console.log(error)}else{console.log(data)}})

Synchronously

Available input types

TypeDescription
stringPath to image file
BufferCreated fromfs.readFile orfs.readFileSync

Example

try{console.log(getSync('image.jpg'))}catch(error){console.log(error)}

Documentation

Contributing

Read thecontribution guidelines.

Changelog

Refer to thechangelog for a full history of the project.

License

ImageData is licensed under theMIT license.


[8]ページ先頭

©2009-2025 Movatter.jp