Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda