You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The error comes when attempting to retrieve and modify an ImageData object in a canvas of type PDF.
It works fine for canvases with only dimensions provided as parameters.
Retrieving ImageData using .getImageData, modifying it, and putting it back fails for canvases of type PDF.
Steps to Reproduce
const{ createCanvas }=require('canvas');constcanvas=createCanvas(200,200,'pdf');constctx=canvas.getContext('2d');// Do something// ...// Later/* Attempted colour inversion of a section (there is another way to achieve this using ctx.globalCompositeOperation and YES that works even for PDF type canvases)*/constvalue=ctx.getImageData(0,0,100,100);constdata=value.data;for(leti=0;i<data.length;i+=4){data[i]=255-data[i];// Reddata[i+1]=255-data[i+1];// Greendata[i+2]=255-data[i+2];// Blue}consttmpCanvas=createCanvas(100,100);consttmpCtx=tmpCanvas.getContext('2d');tmpCtx.putImageData(value,0,0);value=tmpCanvas.toDataURL();
Your Environment
Version of node-canvas (output of npm list canvas or yarn list canvas): 2.8.0
Environment (e.g. node 4.2.0 on Mac OS X 10.8): Tested on Node.js v14.17.3 and v15.6.0 on Ubuntu 20.04 WSL.
The text was updated successfully, but these errors were encountered:
It's not possible to work with image data (pixel values) for a PDF or SVG canvas. #1961 will make this throw an error instead of crashing the process. Thanks for finding the bug.
The error comes when attempting to retrieve and modify an ImageData object in a canvas of type
PDF
.It works fine for canvases with only dimensions provided as parameters.
Issue or Feature
Retrieving
ImageData
using.getImageData
, modifying it, and putting it back fails for canvases of typePDF
.Steps to Reproduce
Your Environment
npm list canvas
oryarn list canvas
): 2.8.0The text was updated successfully, but these errors were encountered: