Using Python 3.4 and Pillow and the method transform: AttributeError: Image

Using Python 3.4 and Pillow and the method transform: AttributeError: Image

我已尝试正确制作以下脚本 运行:

def tftest():
    from PIL import Image
    picture = "ttamet3dim.png"
    impict = Image.open(picture)
    transf = impict.Image.transform((78,78), Image.QUAD, (78,41,178,27,183,91,81,91), Image.BICUBIC)
    imt = Image.open(transf)
    imt.show()

但我收到以下错误:

File "C:\Python34\tftest.py", line 5, in tftest
    transf = impict.Image.transform(...)
File "C:\Python34\lib\site-packages\pillow-3.0.0-py3.4-win32.egg\PIL\Image.py", line 626, in __getattr__
AttributeError: Image

第一次使用"transform"。我想看看 "transform" 脚本,看看我是否能找出问题所在,但我的 Pillow.egg,所以我找不到如何访问代码。您知道我为什么会收到此错误以及如何解决吗? 谢谢,最诚挚的问候

transformImage个对象的方法,returns一个新图像:

from PIL import Image

def tftest():
    picture = "ttamet3dim.png"
    impict = Image.open(picture)
    imt = impict.transform((78,78), Image.QUAD, (78,41,178,27,183,91,81,91), Image.BICUBIC)
    imt.show()

尝试将 transf = impict.Image.transform 更改为 transf = impict.transform

您已将 Image 分配给此处的 impict 变量:

impict = Image.open(picture)

你应该引用这个变量,那是打开的图像,转换:

impict.transform

而不是你目前正在做的事情(基本上 Image.open(picture).Image.transform)。