def write_metadata_pil(file, metadata):
 from PIL import Image, PngImagePlugin
 im = Image.open(file)
 meta = PngImagePlugin.PngInfo()
 for (k, v) in metadata.items():
  meta.add_text(k, v, 0)
 im.save(file, 'PNG', pnginfo=meta)
 return True

def write_metadata_pil ( file , metadata ) : from PIL import Image , PngImagePlugin im = Image . open ( file ) meta = PngImagePlugin . PngInfo ( ) for ( k , v ) in metadata . items ( ) : meta . add_text ( k , v , 0 ) im . save ( file , 'PNG' , pnginfo = meta ) return True
enrich the file metadata with metadata dict thanks to pil .