Exif.Canon* tags are treated like an int while they are a tuple

Bug #372646 reported by medhat
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
IntiPunku
New
Undecided
Unassigned
Phatch
Triaged
High
Stani
pyexiv2
New
Undecided
Unassigned

Bug Description

doing the following:

image = pyexiv2.open(image_path)
image.readMetadata()
for key in image.exifKeys():
    self._exif[key] = image[key]

[...something that will destroy the metadata...]

for key in self._exif:
     image[key] = self._exif[key]
image.writeMetadata()

fails while trying to write the 'Exif.Canon.0x000d' tag, pyexiv2 will complain that the value of the tag is not a valid int, but it seems that this tag is a list not an int.

Revision history for this message
Stani (stani) wrote :

This bug is pretty serious, as it also affects Phatch.

Changed in phatch:
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Stani (stani) wrote :
Download full text (4.3 KiB)

Hi Olivier,

This bug is easily reproducible with the following attachment. Just run the small script "copy_exif.py". (The photos were kindly provided by Chad.) Here the error happens with the "Exif.CanonCs.Lens" which has the tuple value (85, 24, 1). pyexiv2 tries convert this to an int. (This was run on Ubuntu 9.04 with pyexiv2 0.1.3)

Do you have time soon to fix it, as I am preparing a new release of Phatch? This is a blocker.

Thanks in advance!

$ ./copy_exif.py
Traceback (most recent call last):
  File "./copy_exif.py", line 7, in <module>
    source.copyMetadataTo(target)
  File "/usr/lib/python2.6/dist-packages/pyexiv2.py", line 748, in copyMetadataTo
    for key in self.exifKeys():
IOError: Image metadata has not been read yet
stani@blue:~/sync/python/phatch/temp/bugs/exif/photos$ ./copy_exif.py
Traceback (most recent call last):
  File "./copy_exif.py", line 10, in <module>
    source.copyMetadataTo(target)
  File "/usr/lib/python2.6/dist-packages/pyexiv2.py", line 749, in copyMetadataTo
    destImage[key] = self[key]
  File "/usr/lib/python2.6/dist-packages/pyexiv2.py", line 594, in __setitem__
    self.__exifTagsDict[key] = ConvertToPythonType(tagFamily, typeName, str(value))
  File "/usr/lib/python2.6/dist-packages/pyexiv2.py", line 354, in ConvertToPythonType
    value = int(tagValue)
ValueError: invalid literal for int() with base 10: '(85, 24, 1)'

Running the same code with some injected print statement on line 594:
print key, value, tagFamily, typeName, str(value)

stani@blue:~/sync/python/phatch/temp/bugs/exif/photos$ ./copy_exif.py
Exif.Image.Make Canon Exif Ascii Canon
Exif.Image.Model Canon EOS 40D Exif Ascii Canon EOS 40D
Exif.Image.Orientation 8 Exif Short 8
Exif.Image.XResolution 72/1 Exif Rational 72/1
Exif.Image.YResolution 72/1 Exif Rational 72/1
Exif.Image.ResolutionUnit 2 Exif Short 2
Exif.Image.DateTime 2009-04-25 19:01:07 Exif Ascii 2009-04-25 19:01:07
Exif.Image.YCbCrPositioning 2 Exif Short 2
Exif.Image.ExifTag 208 Exif Long 208
Exif.Photo.ExposureTime 1/30 Exif Rational 1/30
Exif.Photo.FNumber 35/10 Exif Rational 35/10
Exif.Photo.ExposureProgram 0 Exif Short 0
Exif.Photo.ISOSpeedRatings 400 Exif Short 400
Exif.Photo.ExifVersion 0221 Exif Undefined 0221
Exif.Photo.DateTimeOriginal 2009-04-25 19:01:07 Exif Ascii 2009-04-25 19:01:07
Exif.Photo.DateTimeDigitized 2009-04-25 19:01:07 Exif Ascii 2009-04-25 19:01:07
Exif.Photo.ComponentsConfiguration  Exif Undefined 
Exif.Photo.ShutterSpeedValue 327680/65536 Exif SRational 327680/65536
Exif.Photo.ApertureValue 237568/65536 Exif Rational 237568/65536
Exif.Photo.ExposureBiasValue 0/1 Exif SRational 0/1
Exif.Photo.MeteringMode 5 Exif Short 5
Exif.Photo.Flash 16 Exif Short 16
Exif.Photo.FocalLength 24/1 Exif Rational 24/1
Exif.Photo.MakerNote (...)
Exif.MakerNote.Offset 674 Exif Long 674
Exif.MakerNote.ByteOrder II Exif Ascii II
Exif.CanonCs.0x0000 94 Exif Ascii 94
Exif.CanonCs.Macro 2 Exif Short 2
Exif.CanonCs.Selftimer 0 Exif Short 0
Exif.CanonCs.Quality 3 Exif Short 3
Exif.CanonCs.FlashMode 0 Exif Short 0
Exif.CanonCs.DriveMode 0 Exif Short 0
Exif.CanonCs.0x0006 0 Exif Short 0
Exif.CanonCs.FocusMode 2 Exif Short 2
Exif.CanonCs.0x0008 0 Exif Short 0
Exif.Canon...

Read more...

Stani (stani)
summary: - The 'Exif.Canon.0x000d' is treated like an int while it seems to be a
- list
+ Some Exif tags are treated like an int while they are a tuple
Revision history for this message
Stani (stani) wrote :

If I add try except clauses around the setting of values, I get this error:
Traceback (most recent call last):
  File "./_copy_exif.py", line 34, in <module>
    copy_metadata(source = 'originalwithEXIF.JPG', target = 'AfterPhatchNoEXIF.JPG')
  File "./_copy_exif.py", line 29, in copy_metadata
    target.writeMetadata()
RuntimeError: TIFF array element tag 43 has wrong type

which relates to:
http://dev.exiv2.org/issues/show/593

Revision history for this message
Stani (stani) wrote : Re: Some Exif tags are treated like an int while they are a tuple

Also this discussion is interesting related to this bug:
http://uk.groups.yahoo.com/group/exiv2/message/1472

Stani (stani)
summary: - Some Exif tags are treated like an int while they are a tuple
+ Some Exif tags (Exif.Canon*) are treated like an int while they are a
+ tuple
Revision history for this message
Stani (stani) wrote :

I fixed as good as I could for Phatch. The behaviour now is that Phatch will keep as much metadata as it can instead of saving nothing when a picture has Exif.Canon.* tags. Unfortunately this is not possible for Exif.Canon* tags as it is not supported by exiv2. My temporary workaround is available in phatch/core/lib/_pyexiv2.py.

$ bzr commit -m "fix partly exif bug"
Committing to: /home/stani/sync/python/phatch/trunk/
modified phatch/core/api.py
modified phatch/core/pil.py
modified phatch/core/lib/_pyexiv2.py
Committed revision 583.

@Chad: please try Phatch from upstream (bzr lp:phatch).

summary: - Some Exif tags (Exif.Canon*) are treated like an int while they are a
- tuple
+ Exif.Canon* tags are treated like an int while they are a tuple
Changed in phatch:
assignee: nobody → stani (stani)
status: Confirmed → Triaged
Revision history for this message
fxp (fxp-gmx) wrote :

If this really is a duplicate of bug #311644, then it cannot only be about Canon. When I posted #311644 it was with pictures from a Sony camera that I experienced it.

Revision history for this message
Stani (stani) wrote :

@fxp:
In that bug report there were two types of pictures attached:
- Sony DSC02994.jpg
- Canon photos.zip

The Sony picture worked perfectly with Phatch. So I suspect something went wrong with your installation of pyexiv2. The metadata of the Canon photos could not be saved with Phatch.

So technically I could have split bug #311644 in two bugs, one for sony and one for canon. The sony one would be tagged "invalid" as I can't reproduce it. And the canon would be a duplicate of this bug. As my free time is valuable, I chose this shortcut. As you insist, I'll decouple your bug.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.