I tried everything to get this work but didn't happen. Want a method to combine two images (that they are overlayed somehow).
I tried it like described here: Merge Image using Javascript
With this Code:
var c=document.createElement("canvas"); c.width = 100; c.height = 100; var ctx=c.getContext("2d"); var imageObj1 = new Image(); imageObj1.src = base64String; var imageObj2 = new Image(); imageObj1.onload = function() { ctx.drawImage(imageObj1, 0, 0, 328, 526); imageObj2.src = "2.png"; imageObj2.onload = function() { ctx.drawImage(imageObj2, 15, 85, 300, 300); var img = c.toDataURL("image/png"); } }; But it doesn't work.
I get the first image by Base64 from Local Storage (as described here) like this:
var img = new Image(); img.src = base64String; And the base64 String looks like this: data:image/png;base64,iVBORw0KGgoAAAANS....
Does this somehow break this approach with canvas? Any help is appreciated :) took me already hours and can't figure it out....
100x100canvas size ? because you are trying to draw Image with 328x526 size.imageObj2.src = "2.png";it may not be a valid src, check dev-tool to see ifimageObj2is successfully loaded.imageObj2.src = "www/img/dummy-pic.png";if(image.complete) {call the hander yourself} else {image.onload = handler}.