@andreekeberg/imagedata

中文文档
1.0.2发布于 2020/09/19MITESM + CJS近 30 天下载 1944

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

原始使用文档
文档目录17 节
  1. Supported formats
  2. Installation
  3. Using npm
  4. Using yarn
  5. Getting started
  6. Import as an ES6 module
  7. Import as a CommonJS module
  8. Usage (Browser)
  9. Asynchronously
  10. Synchronously
  11. Usage (Node.js)
  12. Asynchronously
  13. Synchronously
  14. Documentation
  15. Contributing
  16. Changelog
  17. License

ImageData

Version Total Downloads License

Unified method of retrieving an ImageData instance from an image, in both the browser and Node.js, asynchronously or synchronously. Also exports an ImageData polyfill in Node.js, allowing you to type check instances in both environments.

An ImageData 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 an Error if the provided image has not completed loading

Example

const image = 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 from fs.readFile or fs.readFileSync
fs.ReadStreamCreated from fs.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 from fs.readFile or fs.readFileSync

Example

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

Documentation

Contributing

Read the contribution guidelines.

Changelog

Refer to the changelog for a full history of the project.

License

ImageData is licensed under the MIT license.

版本与发布记录

@andreekeberg/imagedata 共发布 3 个版本,首次发布于 2020/09/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.2latest2020/09/196 年前
1.0.12020/09/156 年前
1.0.02020/09/156 年前

关于 @andreekeberg/imagedata 的常见问题

@andreekeberg/imagedata 是什么?

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

如何安装 @andreekeberg/imagedata?

在项目目录运行 npm install @andreekeberg/imagedata,或使用 pnpm add / yarn add / bun add。

@andreekeberg/imagedata 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/andreekeberg__imagedata 是否存在。

@andreekeberg/imagedata 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@andreekeberg/imagedata 可以商用吗?

@andreekeberg/imagedata 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@andreekeberg/imagedata 的下载量有多少?

根据 npm 官方下载统计,@andreekeberg/imagedata 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,944 次,日均约 65 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@andreekeberg/imagedata 还在维护吗?

最新版本 1.0.2 发布于 2020/09/19(6 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/09/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。