-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
When creating an image with node-canvas inside Google Cloud Functions, the resulting image does not render simple text correctly. Instead of the expected text, the output appears as corrupted, displaying rectangles.
Deployed a Google Cloud Function with Node 22 (Ubuntu 22).
Installed canvas version ^3.2.0.
Used the following example code:
const functions = require('@google-cloud/functions-framework');
const { createCanvas, loadImage } = require("canvas");
functions.http('hello', (req, res) => {
try {
const width = 200;
const height = 200;
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
// Write "Awesome!"
ctx.font = '30px'
ctx.rotate(0.1)
ctx.fillText('Awesome!', 50, 100)
// Output PNG
const buffer = canvas.toBuffer("image/png");
res.set("Content-Type", "image/png");
res.send(buffer);
} catch (err) {
console.error(err);
res.status(500).send("Render error");
}
});
Expected behavior
The PNG should display the text "Awesome!" clearly.
Actual behavior
The text does not render correctly — it appears corrupted, or replaced by strange shapes.
This works correctly in local Node 22 environment.
Metadata
Metadata
Assignees
Labels
No labels