I’m getting stated with HTML5.
When I load images onto a browser, i can use normal HTML <img> tag, and in HTML5, I can also use – canvas- drawImage().
I don’t known what is the differences between <img> and drawImage() when load webpages in browser.
Anyone can make me clear???
The
<img>tag takes an image source and places it in your DOM. The DOM element can then be selected from your document object model withJavaScriptand it can be modified (attributes can be added or removed, source can be changed, etc.)drawImage()takes pixel data and visualizes it in a<canvas>element. Afterwards only the canvas element can be interacted with (selected with javascript). The pixel data can be modified but you cannot utilize attributes liketitle,alt, etc. out of the box like you could with the<img>tag.Use the
<img>tag if you would like simply to render images inside your web page. Use the<canvas>if you want to interact with the images after they have been rendered and you want to perform modifications to the pixel data (for example to draw on top of the image).Example:
<img>:Canvas: