def unbake(imageFile):
"""
Return the openbadges content contained in a baked PNG file.
If this doesn't work, return None.
If there is both an iTXt and tEXt chunk with keyword openbadges,
the iTXt chunk content will be returned.
"""
reader = png.Reader(file=imageFile)
for chunktype, content in reader.chunks():
if chunktype == 'iTXt' and content.startswith(b'openbadges\x00'):
return re.sub(b'openbadges[\x00]+', b'', content).decode('utf8')
elif chunktype == 'tEXt' and content.startswith(b'openbadges\x00'):
return content.split('\x00')[1].decode('utf8')
评论列表
文章目录