D
D
Den182021-10-16 11:26:27
Canvas
Den18, 2021-10-16 11:26:27

How can I change the image to be animated?

With this code, I get a regular image, but I understand that canvas.toBuffer is set to a png image, but I can’t set an image to a gif in this version. If it's not very tricky to change here, then please help.

const Canvas = require('canvas');
const canvas = Canvas.createCanvas(750, 400);
const context = canvas.getContext('2d');
let background = await Canvas.loadImage('./IMG.gif');    
                                                            
  context.drawImage(background, 0, 0, canvas.width, canvas.height);
  
  context.strokeStyle = '#0099ff';
  context.strokeRect(0, 0, canvas.width, canvas.height);
  let buffer = canvas.toBuffer('image/png');
  let attachment = new MessageAttachment(buffer, `${interaction.user.id}.png`);
  return interaction.reply({ files: [attachment] });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question