← Back to team overview

pyexiv2-developers team mailing list archive

Re: Introduction to my aims... and query on a glitch...

 

After the successful install, I have now tested reading and writing most of
the tags that I would find most useful, using pyexiv2. All is well, except
for some of those pesky MS-originated tags, which I still use to retain
backwards compatibility until XP disappears altogether! GNU-Linux rules -
OK?

I am having difficulties with writing these following tags in the required
'byte' format in the the "XP" sub-group:
    Exif.Image.XPTitle
    Exif.Image.XPComment
    Exif.Image.XPAuthor
    Exif.Image.XPKeywords
    Exif.Image.XPSubject

I have used the command pyexiv2.utils.string_to_undefined(sequence) in my
test script to convert the ascii string into the byte format, but after
writing to the image file with metadata.write(), when examining the ensuing
metadata through i.e. "eog" image viewer properties>metadata>details, the XP
metadata displays in Asian characters! This display phenomena is the same
irrespective of which image viewer is used. I also attempted this through
the cli using only exiv2 on a fresh image and with the same strange result.
Perhaps it is an exiv2 issue? Can anyone else reproduce these errors?

Entering the same sequences interactively with the python interpreter gives
the same result - converting with
pyexiv2.utils.string_to_undefined(sequence) seems to work ok and the result
prints out on the cli in oct() byte order as expected, same with
reconverting it the other way with
pyexiv2.utils.undefined_to_string(undefined) - on the cli the ascii chr()
prints out OK. But, as soon as the metadata.write() is issued, the result in
the image file is the strange Asian characters in this "XP" sub-group
(only).

Some further information. I noticed when I extracted these tags in pyexiv2
from a test image containing the complete tags (which had been written
successfully and correctly by another program) and displaying correctly in
image viewers, the extracted result printed in 'byte' format, but each byte
integer was separated by a zero integer thus: " 65 0 97 0 124 0 90 ... " and
so on. When tested on the cli with interactive python doing the conversions,
but before writing the metadata, the result was the expected " 65 97 124 90
..." and so on. Using both forms still results in the erroronous display
when the metadata is written.

I use a bog-standard Linux Ubuntu Karmic (updated fortnightly), my default
language is English no other special settings - gedit or Nano as editors and
python up-to-date and current (2.6).

Any ideas?

-PGG-


On Wed, Sep 15, 2010 at 6:21 PM, Olivier Tilloy <olivier@xxxxxxxxxx> wrote:

> Hi Philip,
>
> (I’m CC’ing the list so that your experiments can benefit everyone, let
> me know if you’d rather continue this exchange privately, and if you
> don’t mind then please use "reply to all")
>
> On 2010-09-15, Philip Graham <philip.graham567@xxxxxxxxx> wrote:
> > Thank you, Oliver again a good response to my queries.
> > No, I did not initially run ldconfig (as root) to update the shared
> > library cache, but I then did so.
> > I am pleased to now be able to report success with installing pyexiv2.
> > I again retraced my steps and re-installed again, and it now seems that
> > it is necessary to have following combination when compiling for Ubuntu
> > Karmic in particular:
> >    - liboost_various versions 1.38, with exiv2 version exiv2-0.19, with
> > pyexiv2-0.2.2. I stress that this is only for my older Karmic
> installation.
>
> Glad you got it up and running!
>
> > Moving on, then, to the use of the metadata tool.
> > I have attached two image files as an example of my desired
> > requirements. The one marked "_original" already contains the full set
> > of metadata as I would want as the end result. I can extract the data
> > using pyexiv2 ok and the result is in
> > "AHVAnsio_CAF35T_108_pyexiv2_data.txt". Using this as an example, I now
> > want place this data back into the other image attached, currently
> > devoid of exif metadata. I am now having difficulty with how to write
> > the desired metadata back into my images. I am not sure of the format of
> > the various text fields. I have read the tag specs on the exiv2 site,
> > but it is the actual formating in the python code. I have tried copying
> > the formats as they have been extracted with metadata.read(). Still
> > experimenting but so far only the "UserComment" [Comment] writes back
> > easily - none of the others seem to write to the tags, I keep getting
> > "KeyError: 'Tag not set'"
> > This will give the error
> >
> >  key = 'Exif.Image.Copyright'
> >  value = '© 1985 Philip G Graham'  # This is the value from the previous
> > metadata.read().
> >  metadata[key].value = value
>
> You’re getting this error because you’re attempting to access the value
> of a tag that doesn’t exist yet. Fortunately you can insert a new tag by
> just passing its value:
>
>    metadata[key] = value
>
> should work in all cases.
>
> >  metadata.write()
>
> Note that if all you want to do is copy metadata from one image to
> another, you should use the copy(…) method:
> http://tilloy.net/dev/pyexiv2/api.html#pyexiv2.metadata.ImageMetadata.copy
> .
>
> > (appending u' to value does not seem to make a difference - I am
> > confused by the subtle differences between text, ascii, bag text,
> > comment, etc)
>
> I agree it’s not crystal clear. Different specifications (EXIF, IPTC,
> XMP) define different types and name them differently. Welcome to the
> twisted world of industry-defined standards…
>
> > but this one writes OK
> >
> >  key = 'Exif.Photo.UserComment'
> >  value = 'AHV Ansio #108 CAF-GE 35T B/n ___ B/d _/71 - 1668 mm. Ansio
> > (Bilbao area) October 1985. Photo taken looking north-west towards
> > Baracaldo (behind loco) underneath the  interchange road of Autopista
> > Solucion Sur in internal yard of AHV Ansio near the loco maintenance
> > workshop.'
> >  metadata[key].value = value
> >  metadata.write()
> >
> > The other strange result is the "XPTagsVarious" being written as literal
> > 'Byte' values. How do I input Ascii text values into these tags in
> > Python? I want these to remain able to display data in the older Windows
> > XP "file>Properties>Details"
>
> Due to the "Byte" nature of this tag, pyexiv2 doesn’t know for sure how
> to interpret those values, so it just prints them out as is.
> To convert ascii text to a byte sequence value, use the
> pyexiv2.utils.string_to_undefined(…) function
> (http://tilloy.net/dev/pyexiv2/api.html#pyexiv2.utils.string_to_undefined)
>
> >
> >  Thanks again
> >
> > -PGG-
>
> I hope this helps!
> Cheers,
>
> Olivier
>

Follow ups

References