node-pureimage icon indicating copy to clipboard operation
node-pureimage copied to clipboard

Path is distorted

Open doublex opened this issue 2 years ago • 0 comments

Expected image:

r

Actual image:

out

Two issues:

  • Second path is missing
  • The top-most pixels are not painted

Steps To Reproduce

import * as PImage from "pureimage"
import * as fs from 'fs'

// make image
const img1 = PImage.make(100, 100)
const ctx = img1.getContext('2d');
ctx.clearRect(0, 0, 100,100)

// <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><path d="M0 0 H40  V100 H0 V60 H20 V40 H0z M60 0 H100 V40 H80 V60 H100 V100 H60z"></path></svg>
// http://www.professorcloud.com/svg-to-canvas/
ctx.fillStyle = "#0000ff";
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(40,0);
ctx.lineTo(40,100);
ctx.lineTo(0,100);
ctx.lineTo(0,60);
ctx.lineTo(20,60);
ctx.lineTo(20,40);
ctx.lineTo(0,40);
ctx.closePath();
ctx.moveTo(60,0);
ctx.lineTo(100,0);
ctx.lineTo(100,40);
ctx.lineTo(80,40);
ctx.lineTo(80,60);
ctx.lineTo(100,60);
ctx.lineTo(100,100);
ctx.lineTo(60,100);
ctx.closePath();
ctx.fill();
ctx.stroke();

PImage.encodePNGToStream(img1, fs.createWriteStream('out.png'));

doublex avatar Apr 17 '23 20:04 doublex