Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skia-canvas not working correctly #9915

Open
emirsassan opened this issue Apr 4, 2024 · 5 comments
Open

skia-canvas not working correctly #9915

emirsassan opened this issue Apr 4, 2024 · 5 comments
Labels
bug Something isn't working needs investigate Needs to be investigated to find the root cause

Comments

@emirsassan
Copy link

What version of Bun is running?

1.1.0+5903a6141

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

import { SlashCommandBuilder } from "@discordjs/builders";
import { Client, CommandInteraction } from "discord.js";
import { Canvas, loadImage, loadFont } from "canvas-constructor/skia";
import { EconomyModel } from "../models/economy";
loadFont("PoppinsBold", "./fonts/Poppins-SemiBold.otf");
loadFont("Poppins", "./fonts/Poppins-Regular.otf");
loadFont("PoppinsMedium", "./fonts/Poppins-Medium.otf");
import {formatNumber} from "../utils/mathUtils";

export default {
  data: new SlashCommandBuilder()
    .setName("bakiye")
    .setDescription("Cüzdanını incele, bakiyeni gör."),
  run: async (client: Client, interaction: CommandInteraction) => {

    let economyData = await EconomyModel.findOne({ id: interaction.user.id });

    //@ts-ignore
    const numberWithCommas = formatNumber(economyData.cash);

    const nick = interaction.user.username;
    const canvas = new Canvas(343, 180);
    const kiremit = await loadImage(`./src/img/bakiye.png`);
    canvas.printImage(kiremit, 0, 0);
    canvas.setColor("#2AD100");
    canvas.setTextAlign("center")
    canvas.setTextFont("14px Poppins");
    canvas.printText(`▲ +$5534 (%32)`, 171, 147);
    canvas.setColor("#D9D9D9");
    canvas.setTextFont("39px PoppinsBold");
    canvas.printText(`$ ${numberWithCommas}`, 171, 91);

    const attachment = canvas.toBuffer("png");

    await interaction.reply({
      content: `> **Bakiye • [ ${nick} ] • <:wallet1:1224509010284118046>**`,
      files: [attachment],
    });
  },
};

or anything that uses skia-canvas for mine thats the thing

What is the expected behavior?

load command and send a image rendered with skia-canvas to channel but bot ignores command since skia-canvas throws an error

What do you see instead?

image

Additional information

No response

@emirsassan emirsassan added the bug Something isn't working label Apr 4, 2024
@Electroid Electroid added the needs investigate Needs to be investigated to find the root cause label Apr 9, 2024
@zfedoran
Copy link

zfedoran commented Apr 10, 2024

Facing the same issue using Docker.

FROM oven/bun:latest

RUN apt-get update
RUN apt-get install -y -q --no-install-recommends libfontconfig1 
RUN bun install skia-canvas

...

Getting the following error

error: Cannot find module "./v6" from "/app/node_modules/skia-canvas/lib/index.js"

I suspect it has something to do with the install flows that skia-canvas expects here:
https://github.com/samizdatco/skia-canvas/blob/main/package.json#L21-L22

@dienstbereit
Copy link

Is there an update here?

I have the same problem on an Ubuntu 20.04 with NGINX 1.18.0.

But...

On my local MacBook installation it runs without any problems.

I am at a loss 🤷‍♂️ Maybe the info that it runs on one system and not the other will help someone.

@emirsassan
Copy link
Author

No update on my side, it still has the same problem, probably a problem with skia-canvas.

@dienstbereit
Copy link

No update on my side, it still has the same problem, probably a problem with skia-canvas.

Thank you for your update. I have swapped skia for @napi-rs/canvas. That seems to work for now.

@TomasHubelbauer
Copy link

TomasHubelbauer commented Dec 4, 2024

I have the same issue and I am also using @napi-rs/canvas in the meanwhile, but unfortunately unlike skia-canvas, it doesn't have support for displaying and drawing into native windows (and interacting with user input), so I hope down the line skia-canvas becomes supported in Bun or they remove the barrier preventing it from working in Bun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs investigate Needs to be investigated to find the root cause
Projects
None yet
Development

No branches or pull requests

5 participants