【问题标题】:How to combine multiple pictures (same size) with PIL in a 2x2 grid?如何在 2x2 网格中将多张图片(相同大小)与 PIL 组合?
【发布时间】:2018-10-18 17:03:15
【问题描述】:
from PIL import Image
# same pic trying to open all 4 in a array
imgs = map(Image.open, ('yeet2.png','yeet2.png','yeet2.png','yeet2.png'))
# creating a blank image
dest = Image.new('RGB', (1500,600))
# creating a 2x2 grid
for x in range(0, 2):
 for y in range(0, 2):
    z = (x + y)
    print(z)
    # not sure how to do the array in paste
    dest.paste(imgs[z], (500 * x, 200 * y))
dest.show()

我知道已经有这样的问题了..我想知道怎么做 只有没有 numpy 的 PIL...

【问题讨论】:

标签: python-3.x image python-imaging-library


【解决方案1】:

我用 python 2.7 和 PIL 测试了你的确切代码,它工作正常。 它应该在 python3 中以相同的方式工作。

您收到的错误信息是什么?

如果您以后想粘贴不同的图像,则必须修复:

z = (x + 2*y)

【讨论】:

  • for y in range(0, h): for x in range(0, w): try: z = z + 1 dest.paste(imgs[z], (width * x, height * y)) 除外:通过
猜你喜欢
  • 2023-03-17
  • 1970-01-01
  • 2012-11-09
  • 1970-01-01
  • 2016-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多