diegomura / jay-peg Goto Github PK
View Code? Open in Web Editor NEWPerformant JPEG decoder
License: MIT License
Performant JPEG decoder
License: MIT License
When I use react-pdf, I'm trying to insert a JPG image but for some reason the image reader fail when he try to decode EXIF metadata.
So i tried to reproduce the minimal code to get the error:
const JPEG = require('jay-peg').default;
const fs = require('fs');
const notWorkingImage = fs.readFileSync('/Users/me/Downloads/not-working.jpg');
JPEG.decode(notWorkingImage);
Leads to:
ReferenceError: IFDHandler is not defined
at $0b53e5b7c7fe341c$var$IDFEntries.decode (/Users/me/Downloads/jpg-test/node_modules/jay-peg/dist/index.cjs:347:36)
at $aa8b66bae6abe658$export$eabc71f011df675a._parseFields (/Users/me/Downloads/jpg-test/node_modules/restructure/dist/main.cjs:750:29)
at $aa8b66bae6abe658$export$eabc71f011df675a.decode (/Users/me/Downloads/jpg-test/node_modules/restructure/dist/main.cjs:721:14)
at $0b53e5b7c7fe341c$var$TIFFHeader.decode (/Users/me/Downloads/jpg-test/node_modules/jay-peg/dist/index.cjs:368:63)
at $fcb208a95f6d048b$export$95a8b60f4da7dec8._parseFields (/Users/me/Downloads/jpg-test/node_modules/restructure/dist/main.cjs:750:29)
at $fcb208a95f6d048b$export$95a8b60f4da7dec8.decode (/Users/me/Downloads/jpg-test/node_modules/restructure/dist/main.cjs:817:14)
at $8ea28a08eae2a116$export$c4be6576ca6fe4aa.decode (/Users/me/Downloads/jpg-test/node_modules/restructure/dist/main.cjs:382:58)
at $8ea28a08eae2a116$export$c4be6576ca6fe4aa.fromBuffer (/Users/me/Downloads/jpg-test/node_modules/restructure/dist/main.cjs:208:21)
at Object.$4fa36e821943b400$var$decode [as decode] (/Users/me/Downloads/jpg-test/node_modules/jay-peg/dist/index.cjs:489:48)
at Object.<anonymous> (/Users/me/Downloads/jpg-test/index.js:7:22)
The line of code who throw the error is:
entries.gpsInfo = IFDHandler(subuffer, $0b53e5b7c7fe341c$var$tags.gps, gps);
And in fact I don't understand what is this IFDHandler
. Cause when I read the sources, the corresponding line of code is:
entries.gpsInfo = this._decodeIDFEntries(buffer, tags.gps, gps, true);
and there is no mention of an IFDHandler
.
Seems like some JPEG encoders stuff extra data after EOI marker (see e.g. https://exiftool.org/forum/index.php?topic=4374.0). We bumped into this in real world usage (with react-pdf).
Would it be possible to end decoding at EOI marker and ignore rest of the data?
Looks like npm run build (or whatever you're using to compile) may not have been ran before npm publish for 1.0.2..
For example, the dist/index.cjs still shows on line 347
entries.gpsInfo = IFDHandler(subuffer, $0b53e5b7c7fe341c$var$tags.gps, gps);
rather than
entries.gpsInfo = this._decodeIDFEntries(buffer, $0b53e5b7c7fe341c$var$tags.gps, gps);
but line 271 is the src/marjers/exif.js in the bundle is as expected:
entries.gpsInfo = this._decodeIDFEntries(buffer, tags.gps, gps, true);
Result being i need to run npm i && npm run build
in the node_modules/jay-peg after npm i
to ensure the issue related to this change is resolved
in exif marker src/markers/exif.js IFDHandler is undefined. so printing an image with geolocation in @react-pdf/renderer will throw an error.
@diegomura tell me if I can help. thanks in advance!
Some JPEGs have a non-standard APP0 segment. It is non-standard but it breaks parsing because jay-peg assumes fixed size APP0.
I can't give the original image but here's the hex for the broken segment: (includes APP0 marker, two-byte size, and the whole marker data)
0xFF,0xE0,0x00,0x14,0x4A,0x46,0x49,0x46,0x00,0x01,0x01,0x01,0x01,0x2C,0x01,0x2C,0x00,0x00,0x41,0x4D,0x50,0x46
The last four bytes spell out AMPF
in ascii, which according to a random googling is somehow related to some Apple extension. See also https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool.pm#L2226
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.