Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I like Drawing Images, too. #2

Open
mpelham opened this issue Sep 6, 2012 · 5 comments
Open

I like Drawing Images, too. #2

mpelham opened this issue Sep 6, 2012 · 5 comments

Comments

@mpelham
Copy link

mpelham commented Sep 6, 2012

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 mpelham closed this as completed Sep 6, 2012
@mpelham mpelham reopened this Sep 6, 2012
@rsaccon
Copy link

rsaccon commented Oct 17, 2012

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

@kanakiyajay
Copy link

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
Copy link

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");
}

@PowerMugen
Copy link

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.

@LukyVj
Copy link

LukyVj commented Feb 9, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants