3
from PIL import Image
from PIL import ImageDraw
from io import BytesIO
from urllib.request import urlopen
url = "https://i.ytimg.com/vi/W4qijIdAPZA/maxresdefault.jpg"
file = BytesIO(urlopen(url).read())
img = Image.open(file)
img = img.convert("RGBA")
draw = ImageDraw.Draw(img, "RGBA")
draw.rectangle(((0, 00), (img.size[0], img.size[1])), fill=(0,0,0,127))
img.save('dark-cat.jpg')
これは私に巨大な黒い四角形を与えています。私はそれが猫と半透明の黒い正方形になりたい。何か案は?PIL画像上に半透明の四角形のオーバーレイを描く
助けてくれてありがとう。私はちょうど新しい問題を作りました:https://github.com/python-pillow/Pillow/issues/2496 –
@ChaseRobertsこれはバグではなく、「描く」が何をすべきか誤解しています。ブレンディングはしません。ピクセルのセットを新しいセットに置き換えます。 [ドキュメントの例](http://pillow.readthedocs.io/ja/3.1.x/reference/ImageDraw.html#example-draw-partial-opacity-text)は、これが2段階のプロセスであることを示しています。空白のキャンバスに不透明で描画し、結果を合成する。この答えの2番目の部分に示すように。 –
@ MarkRansom:確かに、私の回避策はそれを行う方法です(一般的に言えば)。 – martineau