'how can i combine different transparent images via pillow
from PIL import Image
import random
def generate():
img = Image.new('RGBA', (1000, 1000), (255, 0, 0, 0))
possibilities = ['both trees','left tree','right tree']
possibility = random.choice(possibilities)
bg_bot_digit = random.randint(1,12)
bg_top_digit = random.randint(1,12)
currency_digit = random.randint(1,10)
tree_left_digit = random.randint(1,9)
tree_right_digit = random.randint(1,9)
im1 = Image.open(rf"C:\Users\Msi Gaming\Documents\nft\bg top\{bg_top_digit}.PNG").convert("RGBA")
im2 = Image.open(rf"C:\Users\Msi Gaming\Documents\nft\bg bot\{bg_bot_digit}.PNG").convert("RGBA")
im3 = Image.open(rf"C:\Users\Msi Gaming\Documents\nft\currency\{currency_digit}.PNG").convert("RGBA")
im4 = Image.open(rf"C:\Users\Msi Gaming\Documents\nft\tree right\{tree_right_digit}.PNG").convert("RGBA")
im5 = Image.open(rf"C:\Users\Msi Gaming\Documents\nft\tree left\{tree_left_digit}.PNG").convert("RGBA")
if possibility == 'both trees':
img.paste(im1)
img.paste(im2)
img.paste(im3)
img.paste(im4)
img.paste(im5)
if possibility == 'left tree':
img.paste(im1)
img.paste(im2)
img.paste(im3)
img.paste(im5)
if possibility == 'right tree':
img.paste(im1)
img.paste(im2)
img.paste(im3)
img.paste(im4)
img.show()
generate()
I made the images in photoshop and they do not go on top of each other but when i paste them to a transparent background only the last image shows up.Also size does also not matter cause all of them are made with a background which has 1000 pixel width and 1000 pixel height
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
