ここでは、「Pillow」を用いて「Image.alpha_composite()」で指定の画像を重ねる方法について解説しています。
この記事の対象
alpha_composite()の型
Image.alpha_composite(Image1,Image2)
「Image.alpha_composite()」の型は、引数に重ねたい画像をそれぞれ指定するだけです。注意点はどちらも同じサイズでないとエラーが出てしまうことです。
alpha_composite()を用いた使用例
プログラムは、以下の画像を重ね合わせるプログラムになります。


プログラム
from PIL import Image
#1---ファイル
im1 = Image.open("test1.png")
im2 = Image.open("test2.png")
#2---合成
out = Image.alpha_composite(im1, im2)
out.save("comp_result.png")
1の部分でそれぞれの画像を開いています。
#2---合成
out = Image.alpha_composite(im1, im2)
次に2の部分で重ねています。引数にImage1とImage2を指定しています。
結果

画像を重ねることができました。