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:

yes

the end result should (142,86):

yes

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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -