小编Rid*_*kei的帖子

当我使用 PIL 将裁剪粘贴到另一个图像时,它会引发 ValueError

我正准备将 2.jpg 的一小部分粘贴到 1.jpg

from PIL import Image
body = Image.open("1.jpg")
head = Image.open("2.jpg")
headbox = (0,0,30,30)

head.crop(headbox).save("head.jpg")
body.paste("head.jpg", (0,0)).save("out.jpg")
Run Code Online (Sandbox Code Playgroud)

然后它抛出一个错误

  ****************************************, line 8, in <module>
    body.paste("head.jpg", (0,0)).save("out.jpg")
  File "C:\Users\liton\Anaconda3\lib\site-packages\PIL\Image.py", line 1401, in paste
    "cannot determine region size; use 4-item box"
ValueError: cannot determine region size; use 4-item box
Run Code Online (Sandbox Code Playgroud)

我使用 pycharm 和 python 3.7,我没有看到任何语法错误。所以代码怎么了

python-imaging-library python-3.x

6
推荐指数
1
解决办法
5897
查看次数

标签 统计

python-3.x ×1

python-imaging-library ×1