如何将图像裁剪为例如形状.在 Discord.py 中使用 Pillow 循环?
How can I crop an image to a shape for eg. circle using Pillow in Discord.py?
我当前的代码:
@client.event
async def on_member_join(member : discord.Member):
welcome = Image.open('Welcome.jpg')
asset = member.avatar_url_as(size = 128)
data = BytesIO(await asset.read())
pfp = Image.open(data)
pfp = pfp.resize((500, 500))
welcome.paste(pfp, (657, 257))
welcome.save("profile.jpg")
试试这个
import numpy as np
from PIL import Image, ImageDraw
@client.event
async def on_member_join(member : discord.Member):
welcome = Image.open('Welcome.jpg')
asset = member.avatar_url_as(size = 128)
data = BytesIO(await asset.read())
img=Image.open(data).convert("RGB")
npImage=np.array(img)
h,w=img.size
alpha = Image.new('L', img.size,0)
draw = ImageDraw.Draw(alpha)
draw.pieslice([0,0,h,w],0,360,fill=255)
npAlpha=np.array(alpha)
npImage=np.dstack((npImage,npAlpha))
pfp = Image.fromarray(npImage)
welcome.paste(pfp, (657, 257))
welcome.save("profile.jpg")
这篇关于如何将图像裁剪为例如形状.在 Discord.py 中使用 Pillow 圈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!