📜  我可以用 png 文件保存其他信息吗 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:52.375000             🧑  作者: Mango

代码示例1
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'}