thumbnailers.py 文件源码

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

项目:assethub 作者: portnov 项目源码 文件源码
def thumbnail_from_big_image(big_image, size=None):
    try:
        src_w, src_h = get_image_dimensions(big_image)
        img = Image.open(big_image)
        img.thumbnail((512,512))
        th_w, th_h = img.size
        if size is None:
            size = settings.DEFAULT_MAX_THUMB_SIZE
        if th_w > size or th_h > size:
            x = (th_w - size)/2.0
            if x < 0:
                x = 0
            y = (th_h - size)/2.0
            if y < 0:
                y = 0
            img = img.crop((x,y, size+x, size+y))
        output = StringIO()
        img.save(output, format="PNG")
        contents = output.getvalue()
        output.close()
        return ContentFile(contents)
    except IOError:
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号