drewnoakes / metadata-extractor-dotnet

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Other
934 stars 165 forks source link

PNG files with exif preamble #316

Closed reinfallt closed 2 years ago

reinfallt commented 2 years ago

Saving a PNG file with exif info in GIMP contains a 'Exif\x0\x0' preamble but this is not handled by the lib.

Example file: https://drive.google.com/file/d/1v8E2g1oiJDFAkWfzuH8u_g4MkEGVjbE6/view?usp=sharing

In PngMetadataReader.cs, adding a check for the exif preamble fixes the issue but I don't know if it is the "correct" way of solving it:

else if (keyword == "Raw profile type exif" || keyword == "Raw profile type APP1")
{
    if (TryProcessRawProfile(out _))
    {
        int offset = 0;
        if (ExifReader.StartsWithJpegExifPreamble(textBytes))
            offset = ExifReader.JpegSegmentPreambleLength;

        foreach (var exifDirectory in new ExifReader().Extract(new ByteArrayReader(textBytes, offset)))
            yield return exifDirectory;
    }
    else
    {
        yield return ReadTextDirectory(keyword, textBytes, chunkType);
    }
}
drewnoakes commented 2 years ago

@reinfallt your change looks good to me! Would you like to create a pull request?

Also, are you happy to share your PNG file publicly as part of the regression testing dataset?

reinfallt commented 2 years ago

Yes you can include the file in the tests

drewnoakes commented 2 years ago

Thank you!