foliojs / png.js

A (animated) PNG decoder in JavaScript for the HTML5 canvas element and Node.js
http://devongovett.github.com/png.js
MIT License
491 stars 92 forks source link

Trying to manually decode the image in browser - error #6

Closed emirotin closed 11 years ago

emirotin commented 12 years ago

Hi

Doing something in this manner (CoffeeScript, can provide compiled version)

image_url = "/images/ninja.png"
PNG.load image_url, null, (png) ->
    png.decode (pixels) ->
        console.log pixels

Fails here:

data = imageData.data;
length = data.length; // Cannot read property 'length' of undefined 

in .copyToImageData.

devongovett commented 11 years ago

Should be fixed now. Sorry I didn't get to this sooner. Also, the decode method is synchronous in the browser, so the correct usage of the method would look like this:

image_url = "/images/ninja.png"
PNG.load image_url, null, (png) ->
    pixels = png.decode()
    console.log pixels

Thanks for the report!