'JpegImageFile' 对象不可调用

'JpegImageFile' object is not callable

我 运行 在我的脚本末尾遇到了这个错误。错误出现在这段代码的倒数第二行。

for key, i in xylist.iteritems():
    foreground = Image.open(a+str(key)[13:-1]+".jpg")
    background = Image.open("newschedule.jpg")
    x= xylist.get(key)[0]
    y= xylist.get(key)[1]
    background.paste(foreground(x,y), foreground)
background.save("newschedule.jpg")      #must use variable

我收到错误:

    Traceback (most recent call last):
  File "C:\Usersschedule\Scripts\Code\Dictionary + Loop 21.py", line 169, in <module>
    background.paste(foreground(x,y), foreground)
TypeError: 'JpegImageFile' object is not callable
>>> 

有人可以告诉我如何解决这个错误吗?我已经阅读了一些文档,但找不到任何相关内容。

参见:http://effbot.org/imagingbook/image.htm#tag-Image.Image.paste

paste(image, box)

所以你可能需要

background.paste( foreground, (x,y) )

-

顺便说一句:在每个循环中你加载背景但不保存它。也许你应该只加载背景一次 - 在 for 循环之前。

也许你需要:

background = Image.open("newschedule.jpg")

for key, (x, y) in xylist.iteritems():
    filename = "%s%s.jpg" % (a, str(key)[13:-1])
    foreground = Image.open(filename)
    background.paste( foreground, (x,y))

background.save("newschedule.jpg")