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

SVG Text Not Working #759

Closed
jdgamble555 opened this issue Jan 17, 2024 · 1 comment
Closed

SVG Text Not Working #759

jdgamble555 opened this issue Jan 17, 2024 · 1 comment

Comments

@jdgamble555
Copy link

jdgamble555 commented Jan 17, 2024

I'm loading an SVG with Text like so:

const svgImage = `<svg width="1200" height="630" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="blue"/>
<text x="50%" y="50%" font-family="Arial" font-size="40" fill="white"
 text-anchor="middle" alignment-baseline="middle">test</text>
</svg>`;

const canvas = createCanvas(1600, 900);
const ctx = canvas.getContext('2d');

const encoder = new TextEncoder();
const svgBuffer = encoder.encode(svgImage);

//const svgBuffer = Buffer.from(svgImage);
const img = await loadImage(svgBuffer);
ctx.drawImage(img, 0, 0);
const buffer = canvas.toBuffer('image/png');

// print buffer as image...

This prints no text, however, if I add it from the canvas, it works fine:

  // Set text style
  ctx.font = "bold 120px Verdana";
  ctx.textAlign = "center";
  ctx.fillStyle = "white";
  ctx.textBaseline = 'middle';

  let centerX = canvas.width / 2;
  let centerY = canvas.height / 2;

  ctx.fillText('Test', centerX, centerY);

How do I get the SVG text to work?

J

@Brooooooklyn
Copy link
Owner

Fixed in #780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants