Reputation: 37
I noticed that some bots (e.g. MEE6, Arcane, Tatsu, just to name a few) can take a user's profile and add it onto another image. Is there a way to do this in Discord.py? (Sorry if I missed something online or something.)
Upvotes: 3
Views: 2382
Reputation: 2415
This is known as image manipulation
, it can be done in Discord.py with pillow
and it would take and image/s and save it combined with another known as "manipulation"
These are the main imports required from pillow:
from PIL import Image
from io import BytesIO
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageOps
A simple command to produce a user's profile image over a picture can be done below, make sure to put in a picture url or file so it can overwrite it.
@client.command()
async def test(ctx, user: discord.Member = None):
my_image = Image.open("Put your image link or file here")
asset = user.avatar_url_as(size=128)
data = BytesIO(await asset.read())
pfp = Image.open(data)
pfp = pfp.resize((125, 125))
my_image.paste(pfp, (36, 80))
my_image.save("profile.png")
await ctx.send(file=discord.File("profile.png"))
In this example, the bot retrieves the image content first, then stores it. It takes asset
as the user's avatar url and reads it as bytes, however that's too deep to further explain. It then takes both images then positions it, saving the file and sending it.
You can further find more information about pillow in their guide here: https://pillow.readthedocs.io/en/stable/
Upvotes: 3