无法使用PIL或open()打开jpg图像 [英] Cannot open jpg images with PIL or open()
本文介绍了无法使用PIL或open()打开jpg图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在测试将ImageField保存在Django中,但是由于某种原因,我尝试过的所有* .jpg文件都无法工作,而我拥有的一个png却可以工作.在WSL VCode终端中使用django shell.
I am testing to save ImageField in Django, but for some reason all the *.jpg files I've tried don't work while the one png I had works. Using django shell in WSL VCode terminal.
python 3.7
python 3.7
django 3.0
django 3.0
枕头7.1.2
如果我使用open():
If I do with open():
# this has no error
f = open('loko.jpg', 'rb')
#if I do
f.read() # it shows only b'', like its empty
# this saves the field but the image is 0 bytes and cannot be open
object.image.save('name', File(f))
如果我使用PIL:
from PIL import Image
# this shows error
# PIL.UnidentifiedImageError: cannot identify image file 'loko.jpg'
img = Image.open('loko.jpg')
使用我尝试过的.png图像,这两种方法都可以很好地工作.
With the .png image I've tried, both methods work great.
可能是什么问题?
推荐答案
解决方案是更新python-pillow软件包.
Solution was to update the python-pillow package.
现在可以使用了.
这篇关于无法使用PIL或open()打开jpg图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文