如何让粘贴的图片背景透亮?

问题描述 投票:0回答:2

代码:

from PIL import Image, ImageDraw
import requests

img = Image.new('RGBA', (500, 500), 'black')
canvas = ImageDraw.Draw(img)

logo = Image.open(requests.get('https://api-assets.clashofclans.com/badges/70/-1w_sJci3z0Z8XYk-PT9vDhgJzmgzrhdxPbKAUD298s.png', stream=True).raw)

img.paste(logo.convert('RGBA'))

img.show()

结果是这样的




如何使粘贴的图像完全融合?

我想将粘贴的图像完全整合

python python-requests python-imaging-library png
2个回答
0
投票

只需将

'black'
更改为
(0, 0, 0, 0)

from PIL import Image, ImageDraw
import requests

img = Image.new('RGBA', (500, 500), (0, 0, 0, 0))
canvas = ImageDraw.Draw(img)

logo = Image.open(requests.get('https://api-assets.clashofclans.com/badges/70/-1w_sJci3z0Z8XYk-PT9vDhgJzmgzrhdxPbKAUD298s.png', stream=True).raw)

img.paste(logo.convert('RGBA'))

img.show()

-1
投票
from PIL import Image, ImageDraw
import requests

img = Image.new('RGBA', (500, 500), 'black')
canvas = ImageDraw.Draw(img)

logo = Image.open(requests.get('https://api-assets.clashofclans.com/badges/70/-1w_sJci3z0Z8XYk-PT9vDhgJzmgzrhdxPbKAUD298s.png', stream=True).raw)

img.paste(logo.convert('RGBA'), (0, 0), logo.convert('RGBA')) # (0, 0) is position

img.show()
© www.soinside.com 2019 - 2024. All rights reserved.