tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.32k stars 1.68k forks source link

toCanvas returns a promise that is fulfilled with a canvas object. #140

Open andreasg123 opened 7 years ago

andreasg123 commented 7 years ago

This exposes the result of the draw function while making sure that there is an options object. I wrote this to satisfy #138.

While testing my change, I noticed unexpected results if the DOM node has a margin (e.g., p without an additional style). The margin isn't included when sizing the canvas but the content is drawn in the canvas offset by the margin. It would be good to mention this in the documentation if it cannot be fixed easily.

andreasg123 commented 7 years ago

I don't know why "should render text nodes" failed in CI. I didn't change anything in that part of the code. Other tests calling assertTextRendered still work. The test page uses div so that my earlier remark about margins shouldn't apply here.

andreasg123 commented 7 years ago

I added Travis CI to my fork. The test passes and fails intermittently. When I added log output to assertTextRendered, the recognized text was correct. Without the log output, it failed once and passed the second time. Travis CI had a network issue earlier today that may explain this behavior.

There are other Travis CI log messages that may be related:

Firefox 49.0.0 (Linux 0.0.0) LOG: 'Error while reading CSS rules from http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600', 'SecurityError: The operation is insecure.'
12 07 2017 20:03:59.121:WARN [web-server]: 404: /base/spec/resources/util/not-found
Firefox 49.0.0 (Linux 0.0.0) ERROR: 'cannot fetch resource: /base/spec/resources/util/not-found, status: 404'
12 07 2017 20:03:59.126:WARN [web-server]: 404: /base/spec/resources/util/not-found
tsayen commented 6 years ago

Hi, thanks for contributing! Sorry for my late response. I will merge this PR soon.

jojkos commented 3 years ago

Hello, I would like to use the exposed canvas. Would it be by any chance possible to merge this request and release new version?