tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.21k stars 1.68k forks source link

generate an image of 1920 x1080 size #393

Open yogeshbansal opened 2 years ago

yogeshbansal commented 2 years ago

I have to show the image in browser 600x 400 and on a button click when a user downloads it, I have to generate an image of 1920 x1080 size using this library?

MSCAU commented 2 years ago

In the past I have quickly appended a full size (1920 x 1080) image below the fold (ie. below the visible area of the screen) using something like this:

var img = new Image();
img.src = dataUrl;
var temp = document.body.appendChild(img);
domtoimage.toBlob(temp)
    .then(function (blob) {
        window.saveAs(blob, 'full_size.png');
});
temp.remove();

It all happens in less than 1 second so hopefully the user isn't fully aware.

yogeshbansal commented 2 years ago

@MSCAU thanks for a quick reply, I forgot to mention that, I have some overlay text on the image on the left and right sides. for example

Screen Shot 2021-09-04 at 8 18 11 PM

I am currently doing like this domtoimage .toJpeg(document.getElementById('screen'), {background: 'white', quality: 0.95}) .then(function (dataUrl) { var link = document.createElement('a'); link.download = 'my-image-name.jpeg'; link.href = dataUrl; link.click(); }); here 'Screen' is a div container with image and text as child elements. I have kept the size of the container 600x300(in browser), but during download, I want to change image size from 600x300 to 1920x1080 .

MSCAU commented 2 years ago

@yogeshbansal I suggest you create a Codepen page with all this and we can then see where the problem lies.

Overbord commented 2 years ago

@yogeshbansal Did you solve this? I'm looking to do exactly the same thing.