I am trying to convert a DIV to single image. The div has 4 images in it. I have found the js for "htmltocanvas" but this jquery plugin does not create image with all images present in the div.
Here is the div code which having the images in it and need to be convert into image.
<div id="myJershy">
<!-- Color 3 -->
<img src="grey.gif" id="grey" style="position: fixed; top: 8px; left: 12px; width: 935px;">
<!-- Color 2 -->
<img class="orange" id="orange" src="orange.gif" style="position: fixed; left: 10px; top: 8px;">
<!-- Color 4 -->
<img src="gold.gif" id="gold" style="position: fixed; top: 12px; left: 22px;">
<!-- Color 1 -->
<img class="back" id="black" src="back.gif" style="position: fixed; left: 11px; top: 9px;">
<!-- outline -->
<img class="skel" id="skel" src="outline.gif" style="position: fixed;">
</div>
I have also tried with the below javascript code but not able to get the success.
var htmlcontent = $("#myJershy").html();
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%'>" +
"<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px'>" +
htmlcontent+
"</div>" +
"</foreignObject>" +
"</svg>";
var DOMURL = self.URL || self.webkitURL || self;
var img = new Image();
var svg = new Blob([data], {type: "image/svg+xml;charset=utf-8"});
var url = DOMURL.createObjectURL(svg);
img.onload = function() {
ctx.drawImage(img, 0, 0);
DOMURL.revokeObjectURL(url);
};
document.getElementById('previewproduct').src = url;
Please note "html div" has multiple images.