[EMAIL PROTECTED] wrote:
Quoting Alexandre Rossi <[EMAIL PROTECTED]>:

Hi,

But there a problem for IMG_0870_exiftool_usercomment_unicode.JPG : the
exif
is in big endian format. And it this case it seems it is UTF-16BE that
should be used.
Thanks a lot, this should be okay for your examples now.

Not really, I wasn't clear enought. The exif data could be in little or big
endian. In order to know that there is a byte order field in jpeg or exif data
(II or MM).
If the exif data is in little endian, utf-16le should be used
If the exif data is in bug endian, utf-16le should be used.
http://castet.matthieu.free.fr/tmp/test_exif/IMG_0870_exiftool_usercomment_unicode.JPG
is in big endian,
http://castet.matthieu.free.fr/tmp/test_exif/IMG_0874_exiftool_usercomment_unicode.JPG
is in little endian.

But I don't know how to get the bit order info in python.

Waiting for a cleaner solution, a quick hack could be to use im.app['APP1'][6:8].
I attach a patch that does that.

Matthieu

diff -rN -u old-lazygal/lazygal/metadata.py new-lazygal/lazygal/metadata.py
--- old-lazygal/lazygal/metadata.py	2008-06-18 21:23:57.000000000 +0200
+++ new-lazygal/lazygal/metadata.py	2008-06-18 21:23:57.000000000 +0200
@@ -207,7 +207,15 @@
             text = ret
 
         if cset == 'Unicode':
-            encoding = 'utf-16be'
+            im = Image.open(self.image_path)
+            endian = im.app['APP1'][6:8]
+            if endian == 'MM':
+                encoding = 'utf-16be'
+            elif endian == 'II':
+                encoding = 'utf-16le'
+            else:
+                return ''
+
         elif cset == 'Ascii':
             encoding = 'ascii'
         elif cset == 'Jis':

Reply via email to