0

I am creating pages in Scribus via scripting to place text and images. I wish to use pyexviv2 to read/write Exif XPKeywords. Reading from is fine by using 'human_value' to convert from the byte values returned. I realise I do not need to convert except to see that it worked. I am splitting the obtained string from one tag and wish to write one part to another tag. I understand that I cannot use 'human_value' in reverse (read only). Can somebody point me in the right direction please? Below, progress so far, obtaining the 5th part of the filename, which works fine.

[EDIT] Adding... metadata['Exif.Image.XPKeywords']=parts[4] to write gives ValueError: Invalid Value.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import scribus #will test that Scribus is running
import pyexiv2
import string

metadata = pyexiv2.ImageMetadata('j:/BOOK/Banns/1.jpg')
metadata.read()

metadata.exif_keys
['Exif.Image.ImageDescription',
 'Exif.Image.DocumentName',
 'Exif.Image.XPComment',
 'Exif.Image.XPAuthor',
 'Exif.Image.XPSubject',
 'Exif.Image.XPKeywords',
 'Exif.Image.DateTime',
 'Exif.Image.Artist',
 'Exif.Image.Copyright',
 'Exif.Image.ExifTag']

tag=metadata['Exif.Image.DocumentName']
txt=tag.human_value
scribus.messageBox("", txt)     #instead of raw_value or just value
parts=txt.split(',',5)         #Split filename at ',' i.e. 5 strings in a List
scribus.messageBox("",parts[4]) #Separate Place from List

1 Answer 1

1

After 4 hours research I have through trial and error found a working answer which may be useful to others.

I added to the question... "metadata['Exif.Image.XPKeywords']=parts[4]" to write gives ValueError: Invalid Value The answer is as follows because XPKeywords is utf-16...

metadata['Exif.Image.XPKeywords']=pyexiv2.utils.string_to_undefined(parts[4].encode('utf-16'))
metadata.write()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.