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

Can't open PNGs created using Windows 8.1's Paint #23

Closed jameswilddev closed 9 years ago

jameswilddev commented 9 years ago

I don't seem to be able to get png-js to load PNGs made in Windows 8.1's Paint on Linux or Windows 8.1.

Repro source:

var PNG = require("png-js")
var png = new PNG("test.png")

Expected behaviour: completes without any errors or visible side effects. Actual behaviour: crashes while constructing the PNG with the following error: C:\Users\jameswilddev\Desktop\node_modules\png-js\png-node.js:140 throw new Error("Incomplete or corrupt PNG file"); ^ Error: Incomplete or corrupt PNG file at new PNG (C:\Users\jameswilddev\Desktop\node_modules\png-js\png-node.js:14 0:17) at Object. (C:\Users\jameswilddev\Desktop\repro\repro.js:2:11) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3

Environment details: Windows 8.1 x64 Node.js v0.10.33 png-js 0.1.1

Ubuntu Linux 14.04.1 LTS (Trusty) Node.js v0.10.35 png-js 0.1.1

I can open this image without a problem in Paint, Chrome or GIMP. Have attached but don't know if GitHub will do any pre-processing on it which will fix it, so I've also uploaded it to my Cloud9 at:

https://sunruse-jameswilddev.c9.io/test.png

test

Thank you for reading.

devongovett commented 9 years ago

The PNG constructor accepts a buffer of data to read, not a filename. To load a PNG from a file, use PNG.decode to read the file asynchronously, or PNG.load to read it synchronously. See the docs.

Also, I am not really maintaining this project anymore, so if possible, you should try to move to png-stream, which is faster and streaming so it doesn't need to have the whole image in memory at once in order to decode.

jameswilddev commented 9 years ago

Ah, thanks. There's some examples using this library around the net which do exactly this. If the library's deprecated though that's no issue. Thanks.