Skip to content

getImageData behaviour when bounds outside source canvas #1849

Closed

Description

@mijofr

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.

Activity

  1. AugustGSP commented on Nov 17, 2022

    @AugustGSP

    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.

  2. added a commit that references this issue on Jan 11, 2025
    04fefa4
  3. added a commit that references this issue on Jan 13, 2025
    a0c8031
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions