Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
how to make the size of an image in node canvas always be 128 px

so I'm having this problem here. I use node canvas to make image commands for me and my friends in my discord bot, but recently I found out that default discord profile pictures are shown bigger rather than custom ones when drawn over my canvas. Can anyone tell me what I should do in order to make the size of the images drawn over my canvas always be 128 px?

client.on("message", async (message) => {
  if (message.author.bot) return;
  if (message.content.startsWith("R!grave")) {
const canvas = Canvas.createCanvas(800, 450);
let ctx = canvas.getContext('2d');
let pooh = await Canvas.loadImage('./ez.jpg');
ctx.drawImage(pooh, 0, 0, canvas.width, canvas.height);

const [first, second] = [...message.mentions.users.values()]

    if (!first || !second)
      return message.channel.send('You need to mention two users!');


    let avatar1 = await Canvas.loadImage(first.displayAvatarURL({ dynamic: false, format: 'png' }));
    ctx.drawImage(avatar1, 106, 34, avatar1.width * 0.9, avatar1.height * 0.9);
    let avatar2 = await Canvas.loadImage(second.displayAvatarURL({ dynamic: false, format: 'png' }));
    ctx.drawImage(avatar2, 355, 91, avatar2.width * 0.9, avatar2.height * 0.9);




let attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'example.png')



    return message.channel.send(attachment);
  }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can pass fixed width and height values to ctx.drawImage, so canvas always draws it at the same size.

ctx.drawImage(avatar2, 355, 91, 128, 128)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!