我正在使用django的ImageFile来执行以下命令:
>>> f = open("path/image.jpg")
>>> myImage = ImageFile(f)
>>> dim = myImage._get_image_dimensions()
>>> dim
>>> dim is None
True没有显示错误消息,但dim为空,类型为'NoneType‘。
>> myImage.height正因此返回错误消息:
File "some\path\django\core\files\images.py", line 21, in _get_height
return self._get_image_dimensions()[1]
TypeError: 'NoneType' object has no attribute '__getitem__'我在windows7机器上运行python2.7,django 1.6,我的朋友在Mac上尝试了同样的代码,它运行得很好。
发布于 2014-04-17 13:52:26
如果你阅读了code。您将看到get_image_dimensions从文件中读取一个块,并尝试使用PIL将其解析为图像。如果失败,它会增加块大小并重复。(增加块大小是指读取整个文件的读取次数少于(文件大小/初始块大小)次。Fileformats like TIFF need to read the while file.)
3例可能发生返流None。
None,则为https://stackoverflow.com/questions/23125137
复制相似问题