Skip to content
Advertisement

Placing the the user avatar image in the right place in the welcome banner discord.py

I’m trying to place the user name and the user image in the right place in the welcome banner but I can’t mess with pixel well

the banner

this is the output:

output

import  discord

from discord import File
from discord.ext import commands

from easy_pil import Editor
from easy_pil import Font
from easy_pil import load_image_async


bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())

@bot.event
async def on_member_join(member):
    channel = member.guild.system_channel

    background = Editor('assets/welcome.png')
    profile_image = await load_image_async(str(member.avatar.url))

    profile = Editor(profile_image).resize((150,150)).circle_image()
    poppins = Font.poppins(size=50, variant='bold')

    poppins_small = Font.poppins(size=20, variant='light')

    background.paste(profile,(325,90))
    background.ellipse((325,90), 150, 150, outline='white', stroke_width=5)
    background.text((400,260), f'{member.display_name}', color='white', font=poppins, align='center')

    file = File(fp=background.image_bytes,filename='assets/welcome.png')
    await channel.send(file=file)
    await channel.send(f'Hello {member.mention} Welcome To **{member.guild.name} You are the **{len(bot.get_all_members())}th**')

bot.run('')

I was trying to play a little with pixels but I couldn’t fix this right so idk what to do

Advertisement

Answer

If you use paint on windows, you are able to get the pixel coordinates. In pillow, images are loaded based on their top left value. The circle’s x, y length is Absolute value of the difference between the Top Left Hand corner, and the Bottom Right Hand Corner which means the x is 425 – 115 = 310, and the y length is 415 – 105 = 310 (perfect circle). So you should resize to 310,310. The Top Left Hand Corner’s pixel coordinate (Red X on the image) is 115,105 which is where you should paste it instead of (325, 90).

Lastly the text, which should be placed under the image (I’m assuming), all you have to do is get the co-ordinate of the bottom-left hand pixel (green X) and paste it there, which is (115, 415)

Banner

Try this

import  discord

from discord import File
from discord.ext import commands

from easy_pil import Editor
from easy_pil import Font
from easy_pil import load_image_async


bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())

@bot.event
async def on_member_join(member):
    channel = member.guild.system_channel

    background = Editor('assets/welcome.png')
    profile_image = await load_image_async(str(member.avatar.url))

    profile = Editor(profile_image).resize((310,310)).circle_image()
    poppins = Font.poppins(size=50, variant='bold')

    poppins_small = Font.poppins(size=20, variant='light')

    background.paste(profile,(115,105))
    background.ellipse((115,105), 310, 310, outline='white', stroke_width=5)
    background.text((115,415), f'{member.display_name}', color='white', font=poppins, align='center')

    file = File(fp=background.image_bytes,filename='assets/welcome.png')
    await channel.send(file=file)
    await channel.send(f'Hello {member.mention} Welcome To **{member.guild.name} You are the **{len(bot.get_all_members())}th**')

bot.run('')
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement