Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nnirror opened this issue May 3, 2023 · 1 comment
Open

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

nnirror opened this issue May 3, 2023 · 1 comment
Assignees

Comments

@nnirror
Copy link

nnirror commented May 3, 2023

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
Copy link
Author

nnirror commented May 3, 2023

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

lol

@brycebaril brycebaril self-assigned this Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants