pngparse

2019-06-24 admin

pngparse是什么

什么是pngparse,convert PNG images to pixel arrays without dependencies

pngparse使用教程帮助文档

pngparse

PLEASE NOTE THAT THIS LIBRARY IS NO LONGER ACTIVELY MAINTAINED. USE AT YOUR OWN RISK.

You can also use other libraries, such as UPNG.js or pngjs.


pngparse is a pure-JavaScript library for Node.JS for converting a PNG file into an array of pixel values. It came out of a need for reading PNG images in Node.JS for the Dark Sky API, but all existing libraries either had compilation issues or did not support enough of the PNG standard to be practical.

It’s reasonably complete, covering most PNG color types, depths, and filters; notable omissions are lack of support for 16-bit images and interlacing.

Comments, bug fixes, feature improvements, etc. are all welcome. If you do write code, please ensure that you write tests for it!

Usage

To install:

npm install pngparse

To use:

var pngparse = require("pngparse")

...

pngparse.parse(buffer, function(err, data) {
  if(err)
    throw err

  /* do things! */
})

...

pngparse.parseFile("path/to/file.png", function(err, data) {
  if(err)
    throw err

  /* do things! */
})

The data object returned from the callback bears a striking resemblance to the HTML5 Canvas ImageData object. A notable distinction is that the object returns has a channels property which indicates how many color channels it uses (while an HTML5 ImageData object is always 4-channel). The possible color channel combinations are as follows:

1 channel : grayscale
2 channels: grayscale + alpha
3 channels: RGB
4 channels: RGBA

If you use the ImageData.prototype.getPixel method, this is handled for you; however, if you access the data array manually, then you will have to be aware of it.

License

To the extend possible by law, The Dark Sky Company, LLC has waived all copyright and related or neighboring rights to this library.

你可能感兴趣的文章:

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-68073.html

文章标题:pngparse

回到顶部