I would like to know how it is possible to set the background image of a canvas to a .png file. I do not want to add the image in the back of the canvas and make the canvas transparent.
I want the user to be able to actually draw on that canvas with the background being the .png image so that I can extract it later as a .png with the drawings that the user made.
You can use this plugin, but for printing purpose i have added some code like
<button onclick="window.print();">Print</button>
and for saving image<button onclick="savePhoto();">Save Picture</button>
checkout this plugin http://www.williammalone.com/articles/create-html5-canvas-javascript-drawing-app
You can draw the image on the canvas and let the user draw on top of that.
The
drawImage()
function will help you with that, see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Using_imagesAs shown in this example, you can apply a background to a
canvas
element through CSS and this background will not be considered part the image, e.g. when fetching the contents throughtoDataURL()
.Here are the contents of the example, for Stack Overflow posterity:
You can give the background image in css :
it will show you canvas back ground image