-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
I can't see any text #628
Comments
Same here |
Could you please provide minimal reproducible code snippets so I can debug it? |
@Brooooooklyn I'm having the same issue The code runs okay on my Mac but in a docker container the text is empty Here's a code snippet
|
@gegtor could you also upload the |
@Brooooooklyn Yes here it is |
I found a fix
|
It works! Thank you! 🥰 |
Could you try 0.1.38 without the workaround? |
@Brooooooklyn I have tested writing text on my image it seems to work great. import fs from "node:fs";
import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas";
// Load your custom font
GlobalFonts.registerFromPath("./ReenieBeanie-Regular.ttf", "myfont");
// Define the image and text properties
const inputImage = "./welcome-template.jpg";
const outputImage = "output-image.jpg";
const text = `Shivam,
I am so happy
to have you!`;
const fontSize = 90;
const xCoordinate = 715;
const yCoordinate = 510;
const lineHeight = fontSize * 0.9;
// Load the input image using Canvas
loadImage(inputImage).then((image) => {
const canvas = createCanvas(image.width, image.height);
const ctx = canvas.getContext("2d");
// Draw the image onto the canvas
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
// Set the text properties
ctx.font = `normal ${fontSize}px "myfont"`;
ctx.fillStyle = "black";
// Draw the text on the image with new lines
const lines = text.split("\n");
lines.forEach((line, index) => {
ctx.fillText(line, xCoordinate, yCoordinate + index * lineHeight);
});
// Save the canvas as an image
const buffer = canvas.toBuffer("image/jpeg", 50);
fs.writeFileSync(outputImage, buffer);
}); |
It does not work for me. No text visible in canvas! Since I am not sure if there is something specific about my Google Cloud Run Please help. I am pretty desperate about this issue! |
@Brooooooklyn We are facing the same issue. The text is shown on local but no on Lambda. Could you please help? |
The problem is fixed, but it's very strange. When I register the file from a Base64 string, it only has a 5% chance of working on Lambda. However, when I register the font from a file, it works fine on Lambda. I guess there is a bug in the GlobalFonts.register method, where it is not waiting for the loading process to complete. |
I've tried using the default font and I tried using
GlobalFonts
with a custom font and it doesn't show any text.Any ideas?
The text was updated successfully, but these errors were encountered: