0

我遇到了问题,我收到的错误消息是,当一切看起来都正常时,我的图像不匹配。我已经在互联网上搜索并了解如何制作至少 2 张图片,但 4 张图片不起作用。

这是我的代码:

#### Generate Images    
for item in all_images:

im1 = Image.open(f'./trait-layers/backgrounds/{background_files[item["Background"]]}.jpg').convert('RGBA')
im2 = Image.open(f'./trait-layers/elephants/{elephant_files[item["Elephant"]]}.png').convert('RGBA')
im3 = Image.open(f'./trait-layers/hats/{hat_files[item["Hat"]]}.png').convert('RGBA')
im4 = Image.open(f'./trait-layers/smoke/{smoke_files[item["Smoke"]]}.png').convert('RGBA')

#Create each composite
com1 = Image.alpha_composite(im1, im2)
com2 = Image.alpha_composite(com1, im3)
com3 = Image.alpha_composite(com2, im4)



#Convert to RGB
rgb_im = com3.convert('RGB')
file_name = str(item["tokenId"]) + ".png"
rgb_im.save("./images/" + file_name)

我收到此错误消息:

  ValueError: images do not match
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/lq/nw0y9p2s6dnglsnqyls1d4qc0000gn/T/ipykernel_93566/2413409998.py in <module>
      9     #Create each composite
     10     com1 = Image.alpha_composite(im1, im2)
---> 11     com2 = Image.alpha_composite(com1, im3)
     12     com3 = Image.alpha_composite(com2, im4)
     13 

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/PIL/Image.py in alpha_composite(im1, im2)
   3042     im1.load()
   3043     im2.load()
-> 3044     return im1._new(core.alpha_composite(im1.im, im2.im))
   3045 
   3046 

ValueError: images do not match
4

2 回答 2

0

还要检查尺寸。所有图像文件应具有相同的大小。

于 2022-01-22T19:02:25.773 回答
0

您需要确保所有图像文件都相同

于 2021-09-14T19:47:45.340 回答