exif-py icon indicating copy to clipboard operation
exif-py copied to clipboard

Serialization of EXIF data for mongodb, JSON etc.

Open jtlz2 opened this issue 4 years ago • 4 comments

I need to be able to serialize the tags dictionary into a format ingestible by mongodb e.g. JSON. Right now all the tags are of <type 'instance'> though.

PIL's image._getexif() does this - while also preserving types such as float, int, bool etc.

Are you able to assist?

Excellent package of course - for which many thanks.

jtlz2 avatar Mar 26 '20 12:03 jtlz2

Is this a duplicate of https://github.com/ianare/exif-py/issues/59 ?

maxlaverse avatar Apr 20 '20 19:04 maxlaverse

I had actually started work on this a while ago, the main problem is not breaking backwards compatibility. The code is a bit hairy on this. You could do a split on the first space in the tag dict...

ianare avatar Jul 31 '20 03:07 ianare

I had actually started work on this a while ago, the main problem is not breaking backwards compatibility. The code is a bit hairy on this. You could do a split on the first space in the tag dict...

Problem isn't the keys but the values, as they are instances and pymongo doesn't know how to handle them.

In my case I do:

            tags = exifread.process_file(f)
            tags = {k:str(v).strip()  for k, v in tags.items()}

to convert output in a new dictionary. I would have submitted a patch with this if the library returned a class where to add this.

I would make sense to create and return the class hdr and that anyone can call tags() or perhaps a new json() method whenever it be needed.

Also, in that chase, I would also replace k for k.replace(' ', '.') in my code above.

tenuki avatar Dec 20 '20 21:12 tenuki

Of course, as it is commented on #59, it would be better if you can avoid to str(v) and keep value's type in json()'s output..

tenuki avatar Dec 20 '20 21:12 tenuki