py3exiv2-team team mailing list archive
-
py3exiv2-team team
-
Mailing list archive
-
Message #00004
Re: Issue with tag Exif.Photo.UserComment
Hi Vincent,
Thanks for your answer.
On Wed, 23 Dec 2020 13:13:09 +0100
Vincent Vande Vyvre <vincent.vande.vyvre@xxxxxxxxxx> wrote:
> The formatting of the datum is not set at the Python level but into
> libexiv2.
Indeed, I found nothing I was looking for in py3exiv2... everything is
managed in the libexiv2, underneath.
I found in the doc of exiv2 how to manage encoding of this specific tag:
https://exiv2.org/doc/exifcomment_8cpp-example.html
This is directly transposed in py3exiv2 and works like a charm.
Finally there is nothing that py3exiv2 is doing badly. I only wish it
would be possible to expose the raw bytes ...
>
> Anyway, I've checked with an old image tagged with pyexiv2 for Python-2
> and I've no problem to read it with py3exiv2.
>
> >>> import pyexiv2
> >>> data = pyexiv2.ImageMetadata("_DSC1538.JPG")
> >>> data.read()
> >>> data['Exif.Photo.UserComment'].value
> 'Parc Léopold'
> >>> data['Exif.Photo.UserComment'].raw_value
> 'Parc Léopold'
>
> >>>
>
>
> You can check also in command line with exiv2 with the command:
>
> exiv2 -K Exif.Photo.UserComment filename.ext
I have been playing a lot with the exiv2 command line tool those last
days. By printing the binary (actually hexadecimal) representation of
that key `Exif.Photo.UserComment`, I found the gexiv2 binding (I have
been using for the last year) was not declaring properly the encoding:
```
$ exiv2 -ph -g UserComment 11h32m01-NIKON_D7500.nef
0x9286 Photo UserComment Undefined 27 27
0000 00 00 00 00 00 00 00 00 44 65 6d 6f 69 73 65 6c ........Demoisel
0010 6c 65 20 63 6f 69 66 66 c3 a9 65 le coiff..e
```
The encoding header is empty (8x \x00) but data were encoded in UTF-8.
This very same image is interpreted like this in py3exiv2:
```
In [3]: m=pyexiv2.ImageMetadata("11h32m01-NIKON_D7500.nef")
In [4]: m.read()
In [5]: v=m["Exif.Photo.UserComment"]
In [7]: str(v)
Out[7]: '<Exif.Photo.UserComment [Comment] = binary comment>'
In [8]: v.value
Out[8]: 'binary comment'
In [9]: v.human_value
Out[9]: 'binary comment'
In [10]: v.raw_value
Out[10]: 'binary comment'
This means I need to fix manually all pictures which have been acquired
this year. Thanks to the Covid, there are many fewer than other years.
In last instance, I can call `exiv2 -ph` in a script an parse the hex
data to rebuild the comment but I would prefer to find a Python based
solution. Probably py3exiv2 is not the appropriate tool for this kind
of hacking.
Thanks for your help,
Jerome
References