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

Set dimensions for an image object #848

Open
JonWallsten opened this issue Nov 24, 2016 · 2 comments
Open

Set dimensions for an image object #848

JonWallsten opened this issue Nov 24, 2016 · 2 comments

Comments

@JonWallsten
Copy link

I've using node-canvas with resemble.js. However I've noticed some differences in the actual result of the image comparison between a real browser and Node. The only thing I've found so far that differs is the following lines of code.

    var hiddenImage = new Image();
    hiddenImage.src = fileData;
    ...
    hiddenImage.width   = images[0].width;
    hiddenImage.height  = images[0].height;
    ...
    hiddenCanvas.getContext('2d').drawImage(hiddenImage, 0, 0, width, height);

I'm not sure that you should actually be able to do it. Cause I don't find any documentation on what you can actually do with the image object. So some clarification on that would be nice.

Issue or Feature

The problem is that the hiddenImage has the same dimensions after I've tried to set them to new values.
So when the image is drawn on the canvas it will have the wrong dimensions. And therefore the comparison fails.

Steps to Reproduce

    var hiddenImage = new Image();
    hiddenImage.src = fileData;
    ...
    hiddenImage.width   = images[0].width;
    hiddenImage.height  = images[0].height;
    ...
    hiddenCanvas.getContext('2d').drawImage(hiddenImage, 0, 0, width, height);

Your Environment

  • Version of node-canvas (e.g. 1.4.0): 1.6.2
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): Node 7.2.0 Window 10 x64
@LinusU
Copy link
Collaborator

LinusU commented Nov 24, 2016

Hmmm, if it works in the browser I guess that we should support it, but I've never seen this documented somewhere...

You can provide the width and height to the drawImage call so there should be no need for it...

@JonWallsten
Copy link
Author

I guess the difference is whether the browser should scale the image as an image object or if the canvas should do it. I guess the difference would be very small. But when comparing images even small changes becomes a problem. However my problem might be something else, so I'll continue to investigate.

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

3 participants