LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
196 stars 39 forks source link

cannot edit Xmp.iptc.Location as expected #91

Closed lipeck closed 2 years ago

lipeck commented 2 years ago

Hello, I am trying to edit as so:

metadata = {
    "Xmp.dc.description": "description",
    "Xmp.photoshop.Headline": "headline",
    "Xmp.iptc.Location": "sublocation",
}
img.modify_xmp(metadata)

result:

img.read_xmp()
{
    "Xmp.iptc.Location": "",
    "Xmp.photoshop.Headline": "headline",
    "Xmp.dc.description": {'lang="x-default"': "description"},
}

It seems to just be this one field. I'm also unable to clear the field or overwrite anything existing.

LeoHsiao1 commented 2 years ago

Hi Referring to this, Xmp.iptc.Location is a common tag. After trying, I can modify it:

>>> img.read_xmp()
{}
>>> img.modify_xmp({"Xmp.iptc.Location": "sublocation"})
>>> img.read_xmp()
{'Xmp.iptc.Location': 'sublocation'}
>>> img.modify_xmp({"Xmp.iptc.Location": "location"})
>>> img.read_xmp()
{'Xmp.iptc.Location': 'location'}

Is it just this picture that cannot be modified?

lipeck commented 2 years ago

Hi, thanks so much for looking into it for me, and also for creating this tool! I'm having this issue with any photo I try to manipulate. I'm working with .NEF raw images, editing the .XMP sidecar files.

LeoHsiao1 commented 2 years ago

Sorry I don't have any raw images. I googled some images and their xmp.iptc.location is editable. According to exiv2's document, is your image not in standard format?

lipeck commented 2 years ago

According to the chart, the file types I'm using should be OK:

Type | Exif mode | IPTC mode | XMP mode | Comment mode | MIME type NEF | ReadWrite | ReadWrite | ReadWrite | - | image/x-nikon-nef XMP | - | - | ReadWrite | - | application/rdf+xml

LeoHsiao1 commented 2 years ago

Can you edit images in normal formats such as JPEG? RAW images are not standardized across different manufacturers. Can you edit other RAW images from Google?

lipeck commented 2 years ago

Hi, my apologies for the slow response. I tested this with fresh .NEF images from Google. it seems that using the same methods, I can write to the location field when it does not already exist, but I cannot overwrite existing metadata. I also cannot write anything if the field already exists in the .XMP with an empty value. Again, it is only the xmp.iptc.location field which this issue appears, I have been writing and overwriting to many others with great success!

edit to add, this field behaves as expected when tested with JPGs but does not with other RAW photos XMP sidecar files, like with .ARW files

LeoHsiao1 commented 2 years ago

I don't know why. Maybe it's because RAW images are not standardized across different manufacturers? I'm sorry I can't solve the problem.

LeoHsiao1 commented 2 years ago

Anyway, the XMP metadata is in XML format and should all be editable. Can you send a uneditable picture to my email?

lipeck commented 2 years ago

No problem, I am baffled as well... I just sent you an email with an image.

LeoHsiao1 commented 2 years ago

Thank you for sending me the test image. I can edit the xmp.iptc.location field on windows10 and ubuntu20.04 :

>>> import pyexiv2
>>> img = pyexiv2.Image('unedited/test1.NEF')
>>> img.read_xmp()
{}
>>> metadata = {'Xmp.dc.description': 'description', 'Xmp.photoshop.Headline': 'headline', 'Xmp.iptc.Location': 'location', 'Xmp.photoshop.TransmissionReference': 'job ID', 'Xmp.photoshop.SupplementalCategories': 'categories'}
>>> img.modify_xmp(metadata)
>>> img.read_xmp()
{'Xmp.dc.description': 'lang="x-default" description', 'Xmp.photoshop.Headline': 'headline', 'Xmp.iptc.Location': 'location', 'Xmp.photoshop.TransmissionReference': 'job ID', 'Xmp.photoshop.SupplementalCategories': ['categories']}
>>> img.modify_xmp({"Xmp.iptc.Location": "sublocation"})
>>> img.read_xmp()['Xmp.iptc.Location']
'sublocation'

But I didn't have a MacOS to test. Have you tried any other computers? Anyway, you can use read_raw_xmp() and modify_raw_xmp() to modify XMP metadata.

lipeck commented 2 years ago

i am using MacOS. it is the same between other macs -- using another system is not a longterm solution to this problem for me. i don't understand why this issue is persisting but it is frustrating. i'll do some tests with read_raw_xmp() etc. but as i am also manipulating JPGs with the same scripts it would really be best to use read_xmp()

LeoHsiao1 commented 2 years ago

Both exiv2 and pyexiv2 distributions include dynamically linked libraries compiled from C++ code. The library may not be compatible with an operating system and cannot be loaded. But I have never had a situation where the library was loaded and some functionality was unavailable.

Thanks for your patience, please provide some more debugging information:

lipeck commented 2 years ago

thanks for your continued help!

pip show pyexiv2:

Name: pyexiv2
Version: 2.7.0
Summary: Read/Write metadata(including EXIF, IPTC, XMP), comment and ICC Profile embedded in digital images.
Home-page: https://github.com/LeoHsiao1/pyexiv2
Author: LeoHsiao
Author-email: leohsiao@foxmail.com
License: GPLv3
Location: /usr/local/lib/python3.9/site-packages
Requires: 
Required-by: 

from python interactive interpreter:

>>> import pyexiv2
>>> img = pyexiv2.Image('test1.NEF')
>>> img.modify_xmp({'Xmp.dc.description': 'Hello', 'Xmp.iptc.Location': 'location'})
>>> img.read_xmp()['Xmp.iptc.Location']
'location'
>>> img.clear_xmp()
>>> img.modify_xmp({'Xmp.dc.description': 'Hello', 'Xmp.iptc.Location': 'Location'})
>>> img.read_xmp()
{'Xmp.dc.description': {'lang="x-default"': 'Hello'}, 'Xmp.iptc.Location': 'Location'}
>>> img.close()

however, I usually write to the .xmp directly --

>>> import pyexiv2
>>> img = pyexiv2.Image('test1.xmp')
>>> img.modify_xmp({'Xmp.dc.description': 'hello', 'Xmp.iptc.Location': 'location'})
>>> img.read_xmp()['Xmp.iptc.Location']
'location'
>>> img.clear_xmp()
>>> img.modify_xmp({'Xmp.dc.description': 'Hello', 'Xmp.iptc.Location': 'Location'})
>>> img.read_xmp()['Xmp.iptc.Location']
'Location'
>>> img.read_xmp()['Xmp.dc.description']
{'lang="x-default"': 'Hello'}
>>> img.close()

i'll try to check on the exiv2 distribution this week.