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

Image is cropped in Firefox #160

Open
1 of 2 tasks
Trictonicmp opened this issue Jan 10, 2024 · 3 comments
Open
1 of 2 tasks

Image is cropped in Firefox #160

Trictonicmp opened this issue Jan 10, 2024 · 3 comments

Comments

@Trictonicmp
Copy link

Use case: description, code

when generating an image, the image appears cropped, adding width property helps but still cropped

const container = document.getElementById("container");
domtoimage
    .toPng(container, {
      width: 490,
    })
    .then(function (dataUrl) {
      let img = document.createElement("img");
      img.src = dataUrl;
      document.body.appendChild(img);
    });

Note, height property seems to do nothing at least in Firefox

Expected behavior

This is a Chrome screenshot

image

Actual behavior (stack traces, console logs etc)

With width property

image

Without

image

Library version

3.2.0

Browsers

  • Chrome 49+
  • Firefox 45+
@Josh961
Copy link

Josh961 commented Feb 1, 2024

Had the same problem in Firefox. Scaling up the image this way (not using the scale property in the options parameter) should fix it for you:

var scale = 2; // make this whatever you want

var dataUrl = await domtoimage.toJpeg(node, {
  width: node.clientWidth * scale,
  height: node.clientHeight * scale,
  style: {
    transform: "scale(" + scale + ")",
    transformOrigin: "top left"
  }
});

var img = new Image();
img.src = dataUrl;
document.body.appendChild(img);

@gabepetersen
Copy link

Thanks @Josh961 - this works perfectly!

@Trictonicmp
Copy link
Author

I believed I had responded to this, but yes, it works perfectly!
Thank you so much @Josh961!!!

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

No branches or pull requests

3 participants