Closed
Description
When drawing an SVG after setting the width and height to a larger value the drawn SVG is scaled incorrectly.
I've put together a minimal reproduction:
index.js
import {createCanvas, loadImage} from "canvas";
import fs from "fs";
function writeImage(image, size, fileName) {
const canvas = createCanvas(size, size);
const ctx = canvas.getContext('2d');
image.width = size;
image.height = size;
ctx.drawImage(image, 0, 0, size, size);
fs.writeFileSync(fileName, canvas.toBuffer());
}
writeImage(await loadImage('./image.svg'), 100, './no scaling.png');
writeImage(await loadImage('./image.svg'), 200, './2x scaling.png');
image.svg
<svg version="1.2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
<circle fill="#ff0000" cx="50" cy="50" r="50"/>
</svg>
I would expect both output images to be visually the same, other than being scaled up, however the scaled one renders the SVG much larger than it should. This works correctly in node-canvas 2.x
node-canvas version | No Scaling | 2x scaling |
---|---|---|
2.11.2 | ![]() |
![]() |
3.1.0 | ![]() |
![]() |
Metadata
Metadata
Assignees
Labels
No labels