png_bakery.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:openbadges-bakery 作者: concentricsky 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号