2016-01-21 183 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")