1from PIL.PngImagePlugin import PngImageFile, PngInfo
2
3targetImage = PngImageFile("pathToImage.png")
4
5metadata = PngInfo()
6metadata.add_text("MyNewString", "A string")
7metadata.add_text("MyNewInt", str(1234))
8
9targetImage.save("NewPath.png", pnginfo=metadata)
10targetImage = PngImageFile("NewPath.png")
11
12print(targetImage.text)
13
14>>> {'MyNewString': 'A string', 'MyNewInt': '1234'}
15