thumb.py 文件源码

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

项目:omnic 作者: michaelpb 项目源码 文件源码
def generate_thumb(self, size, orig_resource, thumb_resource):
        with orig_resource.cache_open() as orig:
            im = self.Image.open(orig)
            im.thumbnail(size)
        with thumb_resource.cache_open('wb') as target:
            if thumb_resource.typestring.ts_format == 'thumb.jpg':
                # Ensure it has no alpha before saving
                p_mode_alpha = (im.mode == 'P' and 'transparency' in im.info)
                if im.mode in ('RGBA', 'LA') or p_mode_alpha:
                    alpha = im.convert('RGBA').split()[-1]
                    no_alpha = self.Image.new("RGB", im.size, (255, 255, 255))
                    no_alpha.paste(im, mask=alpha)
                    no_alpha.save(target, 'JPEG')
                else:
                    im.save(target, 'JPEG')
            else:
                # Save as is
                im.save(target)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号