mattiasw / ExifReader

A JavaScript Exif info parser.
Mozilla Public License 2.0
749 stars 89 forks source link

Newbie question: why are scalar exif properties (like DateTimeOriginal and most others) returned as string arrays? #272

Closed ehahn9 closed 6 months ago

ehahn9 commented 6 months ago

For example:

    'ExifVersion'?: NumberArrayTag,
    'DateTimeOriginal'?: StringArrayTag,
    'DateTimeDigitized'?: StringArrayTag,

As a developer, I was surprised by this, especially since many other values (like ExposureTime) are scalars.

I'm sure I'm missing something! Perhaps it is always safe to use value[0] for such arrays? Thanks for any advice you have on this. It is a fantastic library!!

mattiasw commented 6 months ago

Hi! The value tries to represent how the tags are stored in the image. It's mostly better to just use description unless you really want to make sure the value has the exact format you need, and in that case you may need to dig into the Exif specification to know how to use it, depending on which tag we're talking about.

That ExposureTime (and others) is not an array is probably a bug in the types. Its value is stored as two numbers (numerator and denominator) and should therefore be an array of two numbers. To get the real value for that it's therefore not correct to just use value[0].

I'm less sure about why e.g. DateTimeOriginal is an array of strings (here the type correctly reflects the real value). It shouldn't have to be unless I'm missing something (some tags are repeatable but not this one). Maybe for consistency (hard to remember after 10+ years 😅).

Short answer: try to use description where possible.

ehahn9 commented 6 months ago

thx. I very much appreciate your time on the reply and of course on the library itself!

mattiasw commented 6 months ago

:+1: I will take a look at the suspicious types when I have time. Thanks for bringing it to my attention.