I store metadata in Pillow using PngImageFile
and PngInfo
from the PngImagePlugin
module by following the code from Jonathan Feenstra in this answer: How do I save custom information to a PNG Image file in Python?
The code is :
from PIL.PngImagePlugin import PngImageFile, PngInfo
targetImage = PngImageFile("pathToImage.png")
metadata = PngInfo()
metadata.add_text("MyNewString", "A string")
metadata.add_text("MyNewInt", str(1234))
targetImage.save("NewPath.png", pnginfo=metadata)
targetImage = PngImageFile("NewPath.png")
print(targetImage.text)
>>> {'MyNewString': 'A string', 'MyNewInt': '1234'}
Now, I want to remove the additional metadata that was previously added to the image which is the text string. How do I remove the metadata on the previously added PNG image?