[英]Extending an image (PIL/Pillow)
我可以使用以下代码在基础图像上方绘制黑条(或矩形):
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)
结果:
但是,如何扩展图像的高度,使所述黑色条看起来附着在图像底部边框的下方, 图像本身之外 ?
如果我在上面的代码中移动了offset
,则黑条不能移动到基本图像的边界之外,因此这不是可行的解决方案。
这是一种方法:
new_img
为(base_width, base_height + background.height)
img
粘贴到(0, 0)
new_img
中 background
粘贴到(0, base_height)
new_img
中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.