utils.py 文件源码

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

项目:django-content-gallery 作者: Kemaweyan 项目源码 文件源码
def create_in_memory_image(image, name, size):
    """
    Resizes the image and saves it as InMemoryUploadedFile object
    Returns the InMemoryUploadedFile object with the image data
    """
    output = io.BytesIO()  # create an io object
    # resize the image and save it to the io object
    image_resize(image, output, size)
    # get MIME type of the image
    mime = magic.from_buffer(output.getvalue(), mime=True)
    # create InMemoryUploadedFile using data from the io
    return uploadedfile.InMemoryUploadedFile(output, 'ImageField', name,
        mime, sys.getsizeof(output), None)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号