can i save additional information with png file

Solutions on MaxInterview for can i save additional information with png file by the best coders in the world

showing results for - "can i save additional information with png file"
Lennard
13 Oct 2018
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'}