I’d like the following to be possible:
Let’s say we have reference of an Image:
var img = document.createElement('img');
img.src = "image.png";
I should be able to convert that image to DataURL
:
img.toDataURL(); // returns DataURL of that image just like Canvas#toDataURL();
I should be able to download it as well, but not like:
<a download="filename">
Because the file is downloaded when that anchor tag’s click()
is called either by API or user gesture.
So for <img>
it should be a method: (since we wouldn’t want it to download on click)
img.download('fileName.png');
Now the screenshot()
method on Elements:
Element.screenshot(); // returns an <img> element
This returns a <img>
element so that I don’t have to create an <img>
element and change the src
, it would be done automatically, and now I can easily:
var screenShot = Element.screenshot(); // get <img>
screenShot.download('filename'); // can easily download image
document.body.appendChild(screenShot); // can easily add to DOM