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)
评论列表
文章目录