1

I use IPTCInfo3 in my Python app to write keywords to the IPCT metadata of an image. For some reason if I use info.save() it creates a copy of the original, e.g. it will write the keyword to Clean.JPG but will also create Clean.JPG~ without the keywords.

If I use info.save_as('Clean.jpg') instead (try to force it to overwrite the original), it doesn't write the keywords to the file. Is there a solution to this?

import iptcinfo3

new_keyword = ["cool", "sad", "blah"]
info = iptcinfo3.IPTCInfo('C:/Tmp/IPTCINFO/Clean.JPG')
for keyword in new_keyword:
    if keyword.encode('UTF-8') not in info['keywords']:
        info['keywords'].append(keyword)
info.save()
Clonimus74
  • 19
  • 3

2 Answers2

1

This solution worked for me.

You will have to comment out 2 lines in the iptcinfo3.py file inside the "save_as" method around line 695 of the file.

else:
    tmpfh.close()
    #if os.path.exists(newfile):
    #    shutil.move(newfile, newfile + '~')
    shutil.move(tmpfn, newfile)

This will write inside the original file without creating a new one and leaving the one with ".jpg~" behind.

0

The pypi release of IPTCInfo3 is unfortunately not updated, but the package version on Github has a merged pull request that introduces an overwrite option.

If you call the save method as: .save(options=["overwrite"]) it overwrites the original file with the new IPTC info and does not leave a .jpg~ file behind.

You can install the latest package directly from Github using:

pip install git+https://github.com/james-see/iptcinfo3.git@master

See this answer in case you want to add it to your requirements.txt file.

Saaru Lindestøkke
  • 2,067
  • 1
  • 25
  • 51