[英]Extending an image (PIL/Pillow)
I can use the following code to draw a black strip (or rectangle) atop a base image: 我可以使用以下代码在基础图像上方绘制黑条(或矩形):
base_width, base_height = img.size
background = Image.new('RGBA', (base_width, base_height/3),(0,0,0,146))
offset = (0,base_height/2)
img.paste(background,offset,mask=background)
Result: 结果:
But how do I extend the height of the image such that the said black strip appears attached below the image's bottom border, outside the image itself ? 但是,如何扩展图像的高度,使所述黑色条看起来附着在图像底部边框的下方, 图像本身之外 ?
If I move the offset
in my code above, the black strip can't move beyond the borders of the base image, so that's not a viable solution. 如果我在上面的代码中移动了
offset
,则黑条不能移动到基本图像的边界之外,因此这不是可行的解决方案。
Here's one way: 这是一种方法:
new_img
that is (base_width, base_height + background.height)
in size new_img
为(base_width, base_height + background.height)
img
into new_img
at (0, 0)
img
粘贴到(0, 0)
new_img
中 background
into new_img
at (0, base_height)
background
粘贴到(0, base_height)
new_img
中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.