如何使用 PIL/Pillow 将图像合并到画布中?

编程入门 行业动态 更新时间:2024-10-28 02:30:59
本文介绍了如何使用 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 将图像合并到画布中?

本文发布于:2023-06-08 02:59:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/572852.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:画布   如何使用   图像   并到   Pillow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!