devongovett / exif-reader

A small EXIF image metadata reader
MIT License
152 stars 22 forks source link

Doesn't work with all EXIF images #1

Closed gchudnov closed 9 years ago

gchudnov commented 9 years ago

e.g the following top image contains EXIF metadata http://www.w3.org/MarkUp/Test/xhtml-print/20050519/tests/A_2_1-BF-01.htm but triggers an exception.

'Invalid EXIF data: buffer should start with "Exif".'
devongovett commented 9 years ago

exif-reader does not read JPEG images directly, only raw EXIF data. You need to first extract the EXIF chunk from the JPEG and then pass it to exif-reader. Support for this is built into jpg-stream.

jon49 commented 9 years ago

A simple workaround without pulling in yet another lib.

const img = readFileSync('flower.jpg')
const imageMetadata = exif(img.slice(img.toString('ascii', 0, 100).indexOf('Exif')))

I don't know if that is a bad way to go about it though... :-/

mir1198yusuf commented 1 month ago

@jon49 are we sure Exif identifier will always come within 100 bytes ?