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.
Here's one way:
new_img
that is (base_width, base_height + background.height)
in size img
into new_img
at (0, 0)
background
into new_img
at (0, base_height)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.