Last active
November 14, 2024 13:50
-
-
Save pedroricardo/801c34d3bdae5e5ceb80abf2fb835cb6 to your computer and use it in GitHub Desktop.
Criando Bot Para Discord #8 - Manipulando Imagem [Python] [PT-BR]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import requests | |
from io import BytesIO | |
from PIL import Image, ImageDraw, ImageFont, ImageOps | |
client = discord.Client() | |
# BY PR#3367 | |
@client.event | |
async def on_ready(): | |
print('BOT ONLINE - Olá Mundo!') | |
print(client.user.name) | |
print(client.user.id) | |
print('--------PR-------') | |
@client.event | |
async def on_member_join(member): | |
channel = client.get_channel("430978574833680384") | |
url = requests.get(member.avatar_url) | |
avatar = Image.open(BytesIO(url.content)) | |
avatar = avatar.resize((130, 130)); | |
bigsize = (avatar.size[0] * 3, avatar.size[1] * 3) | |
mask = Image.new('L', bigsize, 0) | |
draw = ImageDraw.Draw(mask) | |
draw.ellipse((0, 0) + bigsize, fill=255) | |
mask = mask.resize(avatar.size, Image.ANTIALIAS) | |
avatar.putalpha(mask) | |
output = ImageOps.fit(avatar, mask.size, centering=(0.5, 0.5)) | |
output.putalpha(mask) | |
output.save('avatar.png') | |
#avatar = Image.open('avatar.png') | |
fundo = Image.open('bemvindo.png') | |
fonte = ImageFont.truetype('BebasNeue.ttf',70) | |
escrever = ImageDraw.Draw(fundo) | |
escrever.text(xy=(180,164), text=member.name,fill=(0,0,0),font=fonte) | |
fundo.paste(avatar, (40, 90), avatar) | |
fundo.save('bv.png') | |
await client.send_file(channel, 'bv.png') | |
client.run('TOKEN') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageFont, ImageOps | |
avatar = Image.open('pr.png') | |
avatar = avatar.resize((130, 130)); | |
bigsize = (avatar.size[0] * 3, avatar.size[1] * 3) | |
mask = Image.new('L', bigsize, 0) | |
draw = ImageDraw.Draw(mask) | |
draw.ellipse((0, 0) + bigsize, fill=255) | |
mask = mask.resize(avatar.size, Image.ANTIALIAS) | |
avatar.putalpha(mask) | |
output = ImageOps.fit(avatar, mask.size, centering=(0.5, 0.5)) | |
output.putalpha(mask) | |
output.save('avatar.png') | |
#avatar = Image.open('avatar.png') | |
fundo = Image.open('bemvindo.png') | |
fonte = ImageFont.truetype('BebasNeue.ttf', 70) | |
escrever = ImageDraw.Draw(fundo) | |
escrever.text(xy=(180,164), text="Novo TuTorial :D", fill=(0, 0, 0), font=fonte) | |
fundo.paste(avatar, (40, 90), avatar) | |
fundo.show('1.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
código do vídeo: https://www.youtube.com/watch?v=pVkeNCYX7JY: