image_strip.py 文件源码

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

项目:iguana 作者: iguana-project 项目源码 文件源码
def strip_img_metadata(in_memory_img):
    if not in_memory_img:
        return None
    content_type = ""
    if type(in_memory_img) == InMemoryUploadedFile:
        content_type = in_memory_img.content_type
    else:
        # XXX some testcases seem to create files with wrong file format. In case of erroneous magic
        #     bytes we do not strip any data.
        # TODO is there something we can do about that?
        pass

    # jpeg
    if content_type == "image/jpeg" or content_type == "image/jpg":
        img = Image.open(in_memory_img)
        img_io_bytes = io.BytesIO()
        img.save(img_io_bytes, format='JPEG')
        new_img = InMemoryUploadedFile(img_io_bytes, None, in_memory_img.name, 'image/jpeg',
                                       img_io_bytes.getbuffer().nbytes, None)
        new_img.seek(0)
        img.close()
        return new_img

    # TODO remove additional metadata for other formats
    return in_memory_img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号