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

Trying to modify ImageData in PDF: FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal. #1853

Closed
paramsiddharth opened this issue Jul 13, 2021 · 1 comment · Fixed by #1961
Closed
Assignees
Labels

Comments

@paramsiddharth
Copy link

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.

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
 1: 0xa6ae50 node::Abort() [/home/param/.nvm/versions/node/v15.6.0/bin/node]
 2: 0x99dc4d node::FatalError(char const*, char const*) [/home/param/.nvm/versions/node/v15.6.0/bin/node]
 3: 0xc4b0aa v8::Utils::ReportApiFailure(char const*, char const*) [/home/param/.nvm/versions/node/v15.6.0/bin/node]
 4: 0x7f1644465324 Context2d::GetImageData(Nan::FunctionCallbackInfo<v8::Value> const&) [/home/param/myprojects/rema/rema/src/node_modules/canvas/build/Release/canvas.node]
 5: 0x7f1644458d58  [/home/param/myprojects/rema/rema/src/node_modules/canvas/build/Release/canvas.node]
 6: 0xcb7d1b  [/home/param/.nvm/versions/node/v15.6.0/bin/node]
 7: 0xcb92cc  [/home/param/.nvm/versions/node/v15.6.0/bin/node]
 8: 0xcb9946 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/home/param/.nvm/versions/node/v15.6.0/bin/node]
 9: 0x14d8b79  [/home/param/.nvm/versions/node/v15.6.0/bin/node]

Issue or Feature

Retrieving ImageData using .getImageData, modifying it, and putting it back fails for canvases of type PDF.

Steps to Reproduce

const { createCanvas } = require('canvas');
const canvas = createCanvas(200, 200, 'pdf');
const ctx = 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)
*/
const value = ctx.getImageData(0, 0, 100, 100);
const data = value.data;
for (let i = 0; i < data.length; i += 4) {
	data[i]     = 255 - data[i];     // Red
	data[i + 1] = 255 - data[i + 1]; // Green
	data[i + 2] = 255 - data[i + 2]; // Blue
}

const tmpCanvas = createCanvas(100, 100);
const tmpCtx = 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.
@zbjornson
Copy link
Collaborator

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.

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

Successfully merging a pull request may close this issue.

2 participants