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

Issue with Responsive SVG and getImage method #1406

Closed
2 tasks done
miniben-90 opened this issue Jan 19, 2018 · 3 comments · Fixed by #2583
Closed
2 tasks done

Issue with Responsive SVG and getImage method #1406

miniben-90 opened this issue Jan 19, 2018 · 3 comments · Fixed by #2583

Comments

@miniben-90
Copy link

miniben-90 commented Jan 19, 2018

  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

Example : https://jsfiddle.net/9dhs999e/9/

when you have a SVG element responsive with height and width define to 100% at the transformation to picture the result is not correct due to the dynamic size of the element and it result with a deformation of the render.
The solution is to pickup the clientWidth and clientHeight to the node and edit height width attributes with the corrects values.

if ( /[0-9]{1,}\%/i.test(node.getAttribute('width')) || /[0-9]{1,}\%/i.test(node.getAttribute('height')) || /[0-9]{1,}\%/i.test(node.style.width) || /[0-9]{1,}\%/i.test(node.style.height) ) { if (!node.clientWidth && !node.clientHeight && node.parentNode) { node.setAttribute('width', window.getComputedStyle(node.parentNode).width); node.setAttribute('height', window.getComputedStyle(node.parentNode).height); } else { node.setAttribute('width', node.clientWidth); node.setAttribute('height', node.clientHeight); } }

Example : https://jsfiddle.net/4fxwwbh8/1/

Specifications:

  • html2canvas version tested with: latest version (1.0.0-alpha.9)
  • Browser & version: Chrome (Version 63.0.3239.132 (Build officiel) (64 bits)), Edge, Firefox (57.0.4 (64 bits))
  • Operating system: Linux, Windows
@willhoney7
Copy link

I've also experienced this! Looks like you found a fix though. Were you able to submit a PR? I didn't see one.

@niklasvh would you accept this fix as a PR if @miniben-90 submitted it?

@miniben-90
Copy link
Author

Hello,
I didn't make a pull request if I have some time this week I will do it.

@rshelnutt
Copy link

Getting this exact same issue as well - been 3 years now, is this be something that's on radar to be resolved?

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