我可以使用以下代码在基本图像上绘制黑色 strip (或矩形):
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)
结果:
但我如何扩展图像的高度,使所述黑色 strip 出现在图像底部边框下方,在图像本身之外?
如果我在上面的代码中移动 offset
,黑色 strip 不能移动到基本图像的边界之外,所以这不是一个可行的解决方案。
最佳答案
这是一种方法:
- 创建一个
new_img
,其大小为(base_width, base_height + background.height)
- 将原来的
img
粘贴到new_img
的(0, 0)
- 将
背景
粘贴到new_img
中(0, base_height)
关于python - 扩展图像 (PIL/Pillow),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43831842/