devongovett / exif-reader

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

Exif from PNGs with eXIf chunk #19

Closed rijkvanzanten closed 1 year ago

rijkvanzanten commented 3 years ago

Hi there!

I just ran into the same issue as https://github.com/devongovett/exif-reader/issues/11 ("Buffer must start with Exif") when using exif-reader on the "exif data" from a PNG. I'm using sharp to extract the metadata (as per the example in that other thread)

const sharp = require('sharp');
const exifReader = require('exif-reader');

sharp('example.png')
  .metadata()
  .then(({ exif }) => {
    const exifProperties = exifReader(exif);
    console.log(exifProperties);
  });

is this supposed to work? Is exif-reader capable of reading the exif data coming from a PNG? I'm assuming the error is thrown because of the format differences between exif data in JPEGs vs "exif" data under metadata chunks in PNGs? 🤔

rijkvanzanten commented 3 years ago

Screenshots taken on a mac seem to "trigger" sharp to think there's exif data, but subsequently fail in exif-reader

Screenshot.2021-01-12.at.19.32.29.zip

lovell commented 3 years ago

This PNG image appears to store its EXIF data in the relatively new eXIf PNG chunk rather than the historic iTXt chunk.

http://www.simplesystems.org/png-group/proposals/eXIf/history/png-proposed-eXIf-chunk-2017-06-08a.html

The eXIf chunk doesn't include the Exif\0 prefix whereas the iTXt chunk does.

(libpng v1.6.32+ supports the eXIf chunk. sharp recently started providing libspng to parse PNG images, which also supports it.)

Are you able to create a PR that updates the following logic to skip ahead 5 bytes when the Exif\0 prefix is found rather than throw when it's not? The image attached to this issue would make a great test case too.

https://github.com/devongovett/exif-reader/blob/2b040eb8bafd7a337fa1c7209b34c64f44dd5db3/index.js#L4-L5

kapouer commented 2 years ago

Hi, I came across this https://github.com/sanity-io/exif-reader/commit/6ee2ee2f243cd6365ff4235a63797615a983fae1 which is precisely what is asked ?

lovell commented 1 year ago

v1.1.0 now available with support for this - please see https://github.com/devongovett/exif-reader/pull/21