pixel-png

Parse PNG to ImageData in cross-platform

Usage no npm install needed!

<script type="module">
  import pixelPng from 'https://cdn.skypack.dev/pixel-png';
</script>

README

PixelPng NPM version Build Status Coverage Status

Sauce Test Status

Parse PNG to ImageData in cross-platform.

Installation

$ npm install pixel-png --save
var pixelPng= require('pixel-png');
console.log(pixelPng); //function

API

pixelPng.parse(file) -> promise.then(images)

return images is Array contains one or more ImageData.

Return the object instead of ImageData at Node.js

var file= 'https://59naga.github.io/fixtures/animated.PNG';

pixelPng.parse(file).then(function(images){
  var i= 0;

  console.log(images.numPlays); // 0(Infinite)

  var nextImage= function(){
    var imageData= images[i++];
    if(imageData==null) return;

    console.log(imageData);
    nextImage();
  }

  nextImage();
});
// { width: 73, height: 73, left: 0, top: 0, delay: 1000, disposeOp: 0, blendOp: 0, data: <Uint8Array ..> }
// { width: 14, height: 24, left: 48, top: 23, delay: 900, disposeOp: 2, blendOp: 1}
// { width: 1, height: 1, left: 0, top: 0, delay: 800, disposeOp: 0, blendOp: 0}
// ...

Related projects

License

MIT