domvas icon indicating copy to clipboard operation
domvas copied to clipboard

I like Drawing Images, too.

Open mpelham opened this issue 12 years ago • 5 comments

var dom = $('<img src="source/asset/img/tile.png"/>').appendTo('body') var dom2 = $('<div id="foo" style="background: url(source/asset/img/tile.png)">Howdy!</div>').appendTo('body')

domvas.toImage(dom[0], function() { ctx.drawImage(this, 0,0); });

Adding an img tag does not seem to render.

Trying a div with a background tag seems to prevent even the div from rendering, let alone rendering just some of the DIV's contents.

(Just making your life harder :D)

mpelham avatar Sep 06 '12 00:09 mpelham

Also having the same problem not being able to draw images. Any ideas on this ?

rsaccon avatar Oct 17 '12 13:10 rsaccon

Partial answer -> get the base64 string of image and this add the image to the XMLSerializer. http://stackoverflow.com/questions/3771649/how-to-show-image-inside-xml

kanakiyajay avatar Apr 05 '13 06:04 kanakiyajay

I found a way to make this work . Convert the src atributes of all images to base64 strings. Here is the code (will require jQuery)

var imgArray = $('img');
for (var i = 0; i < imgArray.length; i++) {

var dataUrl = getBase64Image(imgArray[i]);
$(imgArray[i]).attr('src',dataUrl);

};

function getBase64Image(img) {
                // Create an empty canvas element
                var canvas = document.createElement("canvas");
                canvas.width = img.width;
                canvas.height = img.height;

                // Copy the image contents to the canvas
                var ctx = canvas.getContext("2d");
                ctx.drawImage(img, 0, 0);

                    return canvas.toDataURL("image/png");
}

kanakiyajay avatar Apr 05 '13 07:04 kanakiyajay

Hello, I love this script and I think it would be great to draw images.

I am searching how to achieve this with a loader like this one:

http://www.html5canvastutorials.com/tutorials/html5-canvas-image-loader/

I made more test and the tools already works with css background images, so in my case it can do the trick. But i'll keep on searching.

PowerMugen avatar Jun 06 '13 11:06 PowerMugen

Hello guys, I had the same problem, the solution is to get your image url as a base64 string.

LukyVj avatar Feb 09 '16 17:02 LukyVj