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

Error when drawing images with fractional heights that scale to less than 1px #2408

Closed
cheapsteak opened this issue Nov 3, 2020 · 1 comment · Fixed by #2409
Closed

Error when drawing images with fractional heights that scale to less than 1px #2408

cheapsteak opened this issue Nov 3, 2020 · 1 comment · Fixed by #2409

Comments

@cheapsteak
Copy link
Contributor

Bug reports:

When drawing a background image with an intrinsic width of 1300 and height of 1, scaled down to a width of 650 (using background-size), the height of the image becomes 0.5, which once assigned to canvas.height, gets rounded to 0

const canvas = (this.canvas.ownerDocument as Document).createElement('canvas');
canvas.width = width;
canvas.height = height;

This then triggers an error of

Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.

possible solution

Switch to use canvas.height = Math.max(1, height); in CanvasRenderer.resizeImage

Specifications:

  • html2canvas version tested with: 1.0.0-rc.7
  • Browser & version: Chrome Version 86.0.4240.111 (Official Build) (x86_64)
  • Operating system: MacOS
@Rax-Pc
Copy link

Rax-Pc commented Apr 22, 2021

I do agree, but the branch of master hasn't deal it .

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

Successfully merging a pull request may close this issue.

2 participants