[英]Why is it that my thumbnail PIL function won't work the 2nd time?
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
It seems that my error is "IOError: cannot identify image file"...based on my traceback log. 看来我的错误是“ IOError:无法识别图像文件” ...根据我的追溯日志。
The only thing I can think of is that you are running on Windows, in which case Image.open()
will open a file handler but does not close it. 我唯一能想到的是您正在Windows上运行,在这种情况下Image.open()
将打开文件处理程序,但不会关闭它。 (That behaviour does not occur on Linux/Unix - the file is closed by the end of your code, and it doesn't matter if it isn't anyway). (这种行为在Linux / Unix上不会发生-该文件在您的代码末尾关闭,并且无论如何都没有关系)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.