Answers for "add metadata png PIL"

0

add metadata png PIL

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'}
Posted by: Guest on April-18-2021

Python Answers by Framework

Browse Popular Code Answers by Language