[英]PIL fill background image repeatedly
I have a small background image like this: 我有一个像这样的小背景图片:
it's a smaller than my image size, so I need to draw it repeatedly. 它比我的图像尺寸小,所以我需要反复绘制它。 (think about background-repeat in css)
(想想css中的background-repeat)
I searched a lot and can't find a solution to this....thanks a lot. 我搜索了很多,找不到解决方案....非常感谢。
Based on the code linked to by Marcin, this will tile a background image on a larger one: 根据Marcin链接的代码,这将在较大的一个上平铺背景图像:
from PIL import Image
# Opens an image
bg = Image.open("NOAHB.png")
# The width and height of the background tile
bg_w, bg_h = bg.size
# Creates a new empty image, RGB mode, and size 1000 by 1000
new_im = Image.new('RGB', (1000,1000))
# The width and height of the new image
w, h = new_im.size
# Iterate through a grid, to place the background tile
for i in xrange(0, w, bg_w):
for j in xrange(0, h, bg_h):
# Change brightness of the images, just to emphasise they are unique copies
bg = Image.eval(bg, lambda x: x+(i+j)/1000)
#paste the image at location i, j:
new_im.paste(bg, (i, j))
new_im.show()
Produces this: 产生这个:
Or removing the Image.eval()
line: 或者删除
Image.eval()
行:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.