add metadata png pil

Solutions on MaxInterview for add metadata png pil by the best coders in the world

showing results for - "add metadata png pil"
Kim
07 May 2019
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