How To Convert A Div In A Html Page Into Image Without Using Canvas?
How can we convert a div element into an image without using canvas? The browser that organization currently uses is IE8 and canvas is not compatible with it. I'm looking for a sol
Solution 1:
Yes we can convert a div element into an image by using dom-to-image.
dom-to-image is a library which can turn arbitrary DOM node into a vector (SVG) or raster (PNG or JPEG) image, written in JavaScript.
var node = document.getElementById('my-node'); //assign our dom id to a variable
domtoimage.toPng(node)
.then(function (dataUrl) {
var img = newImage();
img.src = dataUrl;
document.body.appendChild(img); //append the converted image to html body
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
Here is the simple example of converting html dom to image
Post a Comment for "How To Convert A Div In A Html Page Into Image Without Using Canvas?"