def create_thumbnail(f, width=200, height=100): im = Image.open(f) im.thumbnail((width, height), Image.ANTIALIAS) thumbnail_file = StringIO() im.save(thumbnail_file, 'JPEG') thumbnail_file.seek(0) return thumbnail_file
根据我的追溯记录,似乎我的错误是“IOError:无法识别图像文件”....
答案 0 :(得分:2)
我唯一能想到的是你在Windows上运行,在这种情况下Image.open()
会打开文件处理程序,但不会关闭它。 (在Linux / Unix上不会发生这种情况 - 文件在代码结束时关闭,无论如何都不重要。)