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

getImageData behaviour when bounds outside source canvas #1849

Closed
mijofr opened this issue Jul 10, 2021 · 1 comment
Closed

getImageData behaviour when bounds outside source canvas #1849

mijofr opened this issue Jul 10, 2021 · 1 comment

Comments

@mijofr
Copy link

mijofr commented Jul 10, 2021

https://www.w3.org/TR/2dcontext/#pixel-manipulation

Per spec, for getImageData(sx, sy, sw, sh):

it must return an ImageData object representing the underlying pixel data for the area of the canvas denoted by the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh), in canvas coordinate space units. Pixels outside the canvas must be returned as transparent black.

As a result, I would expect that if I had a canvas size 500x500 filled black, and called getImageData(100,100,1000,1000), I would receive an ImageData object of size 1000x1000, with the top-left 400x400 opaque black and the remainder transparent black. Instead, in node-canvas, the bounds of the result are contained by the bounds of the canvas I'm calling getImageData on, and so I would receive an ImageData 400x400 of opaque black.

@AugustGSP
Copy link

AugustGSP commented Nov 17, 2022

Yep seeing the same thing, the imagedata gets cropped even though it shouldn't.

My hacky workaround is to make the canvas larger than it needs to be, i.e adding the overflow as additional "padding" on the canvas, then cropping it to get the final image + imagedata. Would be nice if this wasn't necessary though.

@zbjornson zbjornson added the Bug label Nov 17, 2022
chearon pushed a commit that referenced this issue Jan 11, 2025
fix a crash in getImageData if the rectangle is outside the canvas

return transparent black pixels when getting image data outside the canvas

remove dead code, add comments

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

No branches or pull requests

4 participants