How to merge 2 transparent png's in python Pillow -
i have 2 transparent png images of same size (142,43). trying vertically stack them. 1 of them:
the end result should (142,86):
it should retain transparancy.
i've tried following code:
from pil import image img_list = [image.open("example.png"), image.open("example.png")] bg = image.open("1x1_transparent.png") bg = bg.resize(size=(142, 43*2)) img_list[0] = img_list[0].convert('rgba') bg.paste(img_list[0], (0, 0), img_list[0]) bg.save('final.png')
which imports 1x1 transparent image, resizes final target size, tries put first image on it. not work. saved image 'final.png' shows empty image.
any thoughts doing wrong?
if output doesn't seem sized, it's because of line:
bg.resize(size=(142, 43*2))
resize
returns new version of image, leaving original 1 unmodified. try assigning returned value can additional operations on , save output.
bg = bg.resize(size=(142, 43*2))
Comments
Post a Comment