mindeng / nom-exif

Exif/metadata parsing library written in pure Rust, both image (jpeg/heif/heic/jpg/tiff/raf etc.) and video/audio (mov/mp4/3gp/webm/mkv/mka, etc.) files are supported.
https://crates.io/crates/nom-exif
MIT License
47 stars 7 forks source link

Support for PNG files? #18

Open abhay-agarwal opened 1 week ago

abhay-agarwal commented 1 week ago

The library we have been using for exif data, exif-rs, seems to have issues parsing png files, and breaks with some kinds of IFD issues on many images. Do you have any plans to support png files?

mindeng commented 1 week ago

Of course, I will consider including PNG support in future versions. Thank you for the feedback!

abhay-agarwal commented 1 week ago

I am happy to take a shot at working on this feature, though there is a peculiarity of PNG files that is worth discussing before I start on a feature branch.

PNG files have several kinds of metadata chunks: EXIF -- this encodes standard exif data that can be read as a normal exif block tEXt -- this is a single block that encodes a single key-value pair, basically two ascii bytestrings itxt, ztxt -- these are more complex, internationalized, compressed string blocks

How would you like to deal with these kinds of blocks? The tEXt metadata is quite common for PNG files, but doesn't fit neatly into the IFD format.

In my own little library, I simply treat the tEXt blocks as a set of custom exif tags with IFD 0. However, the logic for that requires a separate iterator to handle that. Secondly, the tEXT blocks are just ascii strings, which may hinder them fitting into the EXIF system, which usually has much more scoped data representations.

mindeng commented 1 week ago

Thank you! I'm glad you're willing to get involved!

I think it could be done like this:

This is just an initial idea and might not have been thoroughly thought through (including naming), so it's for your reference. If you decide to adopt this approach, please add the necessary documentation for the has_txt_key_values method and specify the supported file types.