Python Image Library: AttributeError: 'NoneType' object has no attribute XXX

前端 未结 2 2005
温柔的废话
温柔的废话 2020-12-16 16:02

I opened a picture with PIL, but when I tried to use split() to split the channels I got following error: AttributeError: \'NoneType\' object has no attri

2条回答
  •  抹茶落季
    2020-12-16 16:39

    With googling I found this comment on SO, stating that PIL is sometimes 'lazy' and 'forgets' to load after opening. So you have to do it like this:

    import Image
    img = Image.open('IMG_0007.jpg')
    img.load()
    img.split()
    

    Please +1 also the original comment! This person did the real work.

提交回复
热议问题