#Canvas

6 messages · Page 1 of 1 (latest)

cosmic elbow

Hello, i am trying to attach an image in interaction.reply discord.js
I get this error : const { createCanvas, loadImage } = require('canvas');

code :

async function createCompositeImage(imageUrls) {
    const canvasWidth = 700;
    const canvasHeight = 250;
    const canvas = createCanvas(canvasWidth, canvasHeight);
    const ctx = canvas.getContext('2d');

    // Set the background to transparent
    ctx.fillStyle = 'rgba(0, 0, 0, 0)';
    ctx.fillRect(0, 0, canvasWidth, canvasHeight);

    const img = await loadImage(imageUrls[0]);
    ctx.drawImage(img, 10, 100, 100, 100); // Adjust positioning and size as needed

    // Draw the number
    ctx.fillStyle = 'black';
    ctx.font = '24px Arial';
    ctx.fillText(`Filled Text`, 600, 200); // Adjust position as needed

    // Convert canvas to base64 PNG data
    const attachment = new AttachmentBuilder(await canvas.encode('png'), { name: 'list-image.png' });
    return attachment;
}

                      await createCompositeImage(imageUrls)
                        .then(base64Image => {
                            listImage = base64Image;
                        })
                        .catch(err => {
                            console.error('Error occurred:', err);
                            cmdError = true;
                        });

                    if (cmdError == false && listImage != "") {
                        await interaction.deferReply();
                        const message = await interaction.editReply({
                            content: `Choose an item : `,
                            files: [listImage],
                            fetchReply: true,
                        });
}

Thank you

brittle caveBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
obsidian flume

What's the error you're receiving?

cosmic elbow

I get this error : const { createCanvas, loadImage } = require('canvas');

but now after i installed @napi-rs/canvas instead of canvas
i get this warning now : (node:1290124) ExperimentalWarning: buffer.File is an experimental feature and might change at any time

ocean agate