“JpegImageFile”对象不是callab

2024-04-25 17:03:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我在脚本的末尾遇到了这个错误。错误出现在该代码的最后第二行。在

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

收到错误:

^{pr2}$

有人能告诉我怎么处理这个错误吗?我看了一些文件,但找不到这方面的任何资料。在


Tags: key代码inimage脚本forget错误
1条回答
网友
1楼 · 发布于 2024-04-25 17:03:50

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

paste(image, box)

所以你可能需要

^{pr2}$

-

顺便说一句:在每个循环中,你加载了背景,但你没有保存它。也许您应该只加载一次背景-在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") 

相关问题 更多 >

    热门问题