0

I just started learning python, and tried my hands on creating a discord bot. Here is a code snippet:

prefix = "https://render-tron.appspot.com/screenshot/https://brilliant.org/"
  
@bot.command(pass_context=True)
async def daily(ctx):
    img_url = prefix + "daily-problems/"
    embedVar = discord.Embed(Title = "Brilliant", url = "https://brilliant.org")
    embedVar.set_image(url = img_url)
    await ctx.send(embed = embedVar) 

Output: Image of the bot output

How can I crop the image and then embed it? I tried saving the image from url then crop it using PIL, but it was a lengthy process. Is there any other way to do it?

  • you can't crop if you don't download - but it doesn't mean you have to save it on disk. You can use `io.BytesIO` to create file in memory and use it with `PIL` – furas Jan 03 '21 at 12:38
  • I tried using PIL, but it took a long time. Also I don't necessarily need to crop the image, it just was looking odd. Thanks tho. – Chirag-Singla Jan 04 '21 at 13:09
  • `PIL` can be used to crop, resize, change colors, draw text, draw figures, etc. And `PIL` should work fast. Problem can makes downloading image - it can work slow. – furas Jan 04 '21 at 13:12
  • some example with PIL in discord: [How to make a canvas profile card in discord python bot?](https://stackoverflow.com/questions/61724373/how-to-make-a-canvas-profile-card-in-discord-python-bot) – furas Jan 04 '21 at 13:16
  • Thanks, it worked. It didn't take time. Previously, I followed a lengthy process of cropping the image. Thanks again. – Chirag-Singla Jan 04 '21 at 15:03

0 Answers0