I am trying to achieve something similar to the image below, with the translucent black box with the writing on: Desired
Ignore the fact that they are different images, but I want to achieve a similar translucent rectangle effect like on the image above. The code I currently have is:
from PIL import Image, ImageDraw
img = Image.new('RGBA', (512, 512), (255, 0, 0, 0))
draw = ImageDraw.Draw(img, 'RGBA')
shape = [(0, 512), (512, 308)]
draw.rectangle(shape, fill = 'black')
img.save('foo.png')
img2 = Image.open('final2.png')
Image.alpha_composite(img2, img).save('foo3.png')
This produces the following output:
Output (ignore white border - its just a rough screenshot)
I've tried putalpha but it just makes the black rectangle grey and still opaque. Also, I've tried creating a transparent image with the same size as the image I want the box drawn on (512x512) and then drawing a rectangle at the bottom of that transparent image then using blend, but the colours of the image mess up because of the white image being blended on top.
Any help is appreciated.
EDIT: Still need help!