简体   繁体   English

为什么我的缩略图PIL功能第二次不起作用?

[英]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.

相关问题 为什么我的递归函数不接受第二个参数? - Why is my recursive function not taking a 2nd argument? 为什么 Flask 应用程序没有第二次运行? - Why Flask Application not running 2nd time? 为什么我的 ezgmail.init() function 不起作用? - Why won't my ezgmail.init() function work? 为什么我的碰撞检测功能在类中不起作用? - Why won't my collision detection function work inside a class? 为什么我的字典排序功能不能正常工作? - Why won't my dictionary sorting function work properly? 为什么我的进口 function 不能在 main 中工作? - Why won't my imported function work in main? 为什么在PIL.Image上调整大小/缩略图不起作用? 蟒蛇 - Reason why resize/thumbnail on PIL.Image doesn't work? Python 为什么我随机改变像素颜色不起作用? (带 PIL) - Why my random change of pixel color doesn't work ? (with PIL) 为什么 solve_ivp 对我的 ODE 的二阶非线性系统不起作用? - Why does solve_ivp not work for my 2nd order non-linear system of ODEs? 在列表中查找频率的代码。 计数为 function 的第二个代码工作得很好,但是使用循环的第一个方法不起作用,为什么? - Code to find frequency in a list. The 2nd code the one with the count function works just fine, but 1st method using loops doesn't work, why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM