revisitors / readimage

Read a (jpg, png, gif) image into a standard binary format in memory.
MIT License
14 stars 5 forks source link

Cannot read property '0' of undefined for certain jpgs #4

Open nnirror opened 1 year ago

nnirror commented 1 year ago

When I try to run the following code, it fails with JPEGs that I've exported from the Preview application in MacOS. Here's the node code I'm running:

readimage(fileData, function (err, image) { if (err) { throw image file could not be read correctly. Try re-exporting it with GIMP or another image editor.; } imageData = image; });

It works perfectly with JPEGs that I've exported from GIMP.

Here's the relevant part of the stack from the error

TypeError: Cannot read property '0' of undefined at quantizeAndInverse (/Users/cella/Sites/facet/node_modules/jpeg-js/lib/decoder.js:356:26) at buildComponentData (/Users/cella/Sites/facet/node_modules/jpeg-js/lib/decoder.js:509:9) at constructor.parse (/Users/cella/Sites/facet/node_modules/jpeg-js/lib/decoder.js:772:18) at Object.decode (/Users/cella/Sites/facet/node_modules/jpeg-js/lib/decoder.js:966:11) at parseJpg (/Users/cella/Sites/facet/node_modules/readimage/readimage.js:88:18) at read (/Users/cella/Sites/facet/node_modules/readimage/readimage.js:26:10)

Not sure if if this is helpful, but here's the beginning of the hex of the JPEG that isn't working and was causing this error. I've tried it with other JPEGs exported from Preview and keep getting this same error. Wondering if they write file headers a little differently or something?

<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 90 00 90 00 00 ff e1 00 9e 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 05 01 12 00 03 00 00 00 01 00 01 ... 51105 more bytes>

And here's the beginning of the hex of a JPEG that is working correctly:

<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 02 00 1c 00 1c 00 00 ff e1 36 76 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 07 00 12 01 03 00 01 00 00 00 01 00 ... 267024 more bytes>

nnirror commented 1 year ago

Here's the file that is failing for me, if that's helpful

lol