devongovett / exif-reader

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

PNG, little endian without Exif\0\0 prefix: Invalid EXIF data: buffer should start with "Exif", "MM" or "II". #34

Closed Profesor08 closed 6 months ago

Profesor08 commented 6 months ago

Code

  const sharpImage = sharp(src, { animated: true });

  sharpImage.png({ quality: quality });

  sharpImage.withExif({
    IFD0: {
      Software: `sharp:${quality}`,
    },
  });

  sharpImage.keepMetadata();

  sharpImage.keepExif();

  const buffer = await sharpImage.toBuffer();

  const { exif } = await sharp(buffer).metadata();

  console.log(exif?.toString());

  try {
    if (exif !== undefined) {
      console.log(exif.toString().substring(0, 2) === "II");
      console.log(ExifReader.load(exif));
    }
  } catch (err) {
    console.log(err);
  }

Buffer to string

II↕☺♥☺☺→☺♣☺b☺♣☺(☺♥☺☻1☺☻ r‼☻♥☺☺i�♦☺|x2☻�♥x2☻�♥sharp:80♠�♦0210☺�♦☺☻♥�♦0100☺�♥☺��☻�♦☺�☻♥�♦☺ ♥

Exception

Error: Invalid EXIF data: buffer should start with "Exif", "MM" or "II".
    at module.exports (\node_modules\exif-reader\index.js:8:13)
    at test (\vite.config.ts:130:50)
    at async FSWatcher.<anonymous> (\vite.config.ts:102:5)
lovell commented 6 months ago

PR for this at https://github.com/devongovett/exif-reader/pull/35

lovell commented 6 months ago

v2.0.1 now available with the fix for this.