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

Confirmed it doesn't work on Safari #181

Open
jonrrivera opened this issue Aug 7, 2024 · 4 comments
Open

Confirmed it doesn't work on Safari #181

jonrrivera opened this issue Aug 7, 2024 · 4 comments

Comments

@jonrrivera
Copy link

So dom-to-image-more doesnt work on safari? bummer :/

@IDisposable
Copy link
Member

What's the actual error @jonrrivera ?

@IDisposable
Copy link
Member

Can you verify that v3.4.2 does not work under version Safari 15.4 ?

@djrees
Copy link

djrees commented Sep 3, 2024

It doesn't produce an error, but it does cut off the image when download.

Original element to capture:
Screenshot 2024-09-03 at 12 34 24

Dom-to-image-more output:
download

It has a transparent background, but the image is incorrectly cropped. The original element was 400px by 400px. It happens on both desktop and mobile.

Code used:

let node = 'test';
let file = 'download';
function download(node, file) {
    domtoimage
        .toPng(document.getElementById(node))
        .then(function(dataUrl){
            var link = document.createElement('a');
            link.download = file+".png";
            link.href = dataUrl;
            link.click();
        })
}
<div id="test" style="background: linear-gradient(0, red 0%, blue 100%); width: 400px; height: 400px; display: flex; align-items: center; justify-content: center;">
    <p style="color: white; margin: 0">Hello</p>
</div>

@djrees
Copy link

djrees commented Sep 3, 2024

Follow up: Using Josh961's comment on this Firefox issue, setting the height and width seems to work well.

Solution:

function download(node, file) {
    let element = document.getElementById(node);
    domtoimage
        .toPng(element, {
            width: element.offsetWidth,
            height: element.offsetHeight
        })
        .then(function(dataUrl){
            var link = document.createElement('a');
            link.download = file+".png";
            link.href = dataUrl;
            link.click();
        })
}

New output:
test

Hope this helps! 😊

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