本文介绍了如何使用PIL / Pillow将图像合并到画布中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不熟悉PIL,但我知道很容易把一堆图像放在ImageMagick的网格中。
I'm not familiar with PIL, but I know it's very easy to put a bunch of images into a grid in ImageMagick.
我如何,将16个图像放入4× 4网格中,我可以指定行和列之间的间隙?
How do I, for example, put 16 images into a 4×4 grid where I can specify the gap between rows and columns?
推荐答案在 PIL 中也做。创建空白图片,然后只需使用粘贴。下面是一个简单的例子:
This is easy to do in PIL too. Create an empty image and just paste in the images you want at whatever positions you need using paste. Here's a quick example:
import Image #opens an image: im = Image.open("1_tree.jpg") #creates a new empty image, RGB mode, and size 400 by 400. new_im = Image.new('RGB', (400,400)) #Here I resize my opened image, so it is no bigger than 100,100 im.thumbnail((100,100)) #Iterate through a 4 by 4 grid with 100 spacing, to place my image for i in xrange(0,500,100): for j in xrange(0,500,100): #I change brightness of the images, just to emphasise they are unique copies. im=Image.eval(im,lambda x: x+(i+j)/30) #paste the image at location i,j: new_im.paste(im, (i,j)) new_im.show()
更多推荐
如何使用PIL / Pillow将图像合并到画布中?
发布评论