Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

image - Paste Png Over Png PIL Python

I'm trying to make a generator for images combined. I'm trying to have the images side by side and when It gets to 4 images go down. And I'm trying to paste a gray png over the images with text on it saying the name of that skin or item.

Here's my code so far:

def main():
        image = requests.get("https://fortnite-api.com/v2/cosmetics/br/new").json()
        image_path = image['data']['items']
        for i in image_path:
            if i['rarity']['displayValue'] == 'Legendary':
                filename = f"data/images/{i['id']}.png"
                skin = Image.open(filename, 'r').convert("RGBA")
                filename1 = 'data/assets/Legendary_Background.png'
                bg = Image.open(filename1, 'r')
                text_img = Image.new('RGBA', (512,512), (0, 0, 0, 0))
                text_img.paste(bg, (0,0))
                text_img.paste(skin, (0,0), mask=skin)
                text_img.save(f"data/out/{i['id']}.png", format="png")

Here's the raw images:

Legendary_Background:

Gray Slide:

I want to paste another png on top of the skin so In theory it should look like this:

question from:https://stackoverflow.com/questions/65940355/paste-png-over-png-pil-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this code:

back_im = im1.copy()
back_im.paste(im2, (100, 50))
back_im.save('data/dst/rocket_pillow_paste_pos.jpg', quality=95)

Please make sure you have your images you want to paste in front of the other picture are cropped so there is not background you don't want otherwise it will still go over and ruin the picture.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...