TIM*_*MEX 4 python encoding image file python-imaging-library
我使用Python图像库(PIL)来调整图像大小并创建缩略图.为什么我的代码会生成一个如此糟糕和低质量的图像?有人能告诉我如何修改代码,以便它是最高质量的JPEG?
def create_thumbnail(buffer, width=100, height=100):
im = Image.open(StringIO(buffer))
if im.mode not in ('L', 'RGB', 'RGBA'):
im = im.convert('RGB')
im.thumbnail((width, height), Image.ANTIALIAS)
thumbnail_file = StringIO()
im.save(thumbnail_file, 'JPEG')
thumbnail_file.seek(0)
return thumbnail_file
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3878 次 |
| 最近记录: |