2016-01-21 182 views
0

我碰到了这个错误,直到脚本结束。该错误位于此代码的最后一行。'JpegImageFile'对象不可调用

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 
>>> 

可能有人请让我知道如何解决这个问题?我已阅读了一些文档,但无法找到任何关于此的内容。

+0

'foreground'不是功能 - 你不能叫'前台(X,Y)' – furas

回答

0

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

所以,你可能需要

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

-

BTW:在每一个循环加载的背景,但你不救它。也许你应该只加载一次背景 - 在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")