Render HTML to an image

后端 未结 17 2104
栀梦
栀梦 2020-11-22 16:06

Is there a way to render html to image like PNG? I know that it is possible with canvas but I would like to render standard html element like div for example.

17条回答
  •  臣服心动
    2020-11-22 16:19

    Use html2canvas just include plugin and call method to convert HTML to Canvas then download as image PNG

            html2canvas(document.getElementById("image-wrap")).then(function(canvas) {
                var link = document.createElement("a");
                document.body.appendChild(link);
                link.download = "manpower_efficiency.jpg";
                link.href = canvas.toDataURL();
                link.target = '_blank';
                link.click();
            });
    

    Source: http://www.freakyjolly.com/convert-html-document-into-image-jpg-png-from-canvas/

提交回复
热议问题