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

fix: calculateBackgroundRendering may return width or height less than 1 #2982

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

herbertxy
Copy link

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

image

I console the value of width and height , find that the height is less than 1 caught this error
image
image

calculateBackgroundRendering function return value width height may be less than 1, then createPattern function throw error

Closing issues

Fixes #2981

nicDamours pushed a commit to nicDamours/html2canvas that referenced this pull request Nov 9, 2023
added fix from niklasvh#2982
Added prepare script.
@yorickshan
Copy link

thx for your pr, this fix has been merged to html2canvas-pro

@purplepeng
Copy link

Thanks all. I have the same issue use version 1.4.1. Can you merge the commit and publish a new version ?@niklasvh

@yorickshan
Copy link

Thanks all. I have the same issue use version 1.4.1. Can you merge the commit and publish a new version ?@niklasvh

Feel free to try using html2canvas-pro v1.5.6 or the most recent version.

@purplepeng
Copy link

purplepeng commented Jul 15, 2024

Thanks all. I have the same issue use version 1.4.1. Can you merge the commit and publish a new version ?@niklasvh

Feel free to try using html2canvas-pro v1.5.6 or the most recent version.

@yorickshan I try to use your repo version, but the image convert from canvas is not right. With same options used in html2canvas, i can get right image.

html2canvas(element, { useCORS: true, allowTaint: true, backgroundColor: null })
  .then((canvas) => {
    if (canvas) {
      console.log('canvas', canvas);
      const data = canvas?.toDataURL('image/png');
      resolve({ data });
    } else {
      reject();
    }
  })

image
use html2canvas-pro

image
use html2canvas

@yorickshan
Copy link

yorickshan commented Jul 16, 2024

Thanks all. I have the same issue use version 1.4.1. Can you merge the commit and publish a new version ?@niklasvh

Feel free to try using html2canvas-pro v1.5.6 or the most recent version.

@yorickshan I try to use your repo version, but the image convert from canvas is not right. With same options used in html2canvas, i can get right image.

html2canvas(element, { useCORS: true, allowTaint: true, backgroundColor: null })
  .then((canvas) => {
    if (canvas) {
      console.log('canvas', canvas);
      const data = canvas?.toDataURL('image/png');
      resolve({ data });
    } else {
      reject();
    }
  })

image use html2canvas-pro

image use html2canvas

I didn't reproduce the issue using the latest version (1.5.6). Please feel free to submit a detailed issue to html2canvas-pro, preferably with a minimal demo.

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