JSFiddle - React, Tailwind, and code Playground
HTML
Source:<br><img src="https://www.google.com/images/errors/logo_sm.gif" alt="Google" id="google_logo"><br>
Copy:<br>
JavaScript
function ready() {
var imgSource = document.getElementById('google_logo');
var canvas = document.createElement('canvas');
canvas.id = 'myCanvas';
var ctx = canvas.getContext('2d');
canvas.setAttribute('width', imgSource.width);
canvas.setAttribute('height', imgSource.height);
ctx.drawImage(imgSource, 0, 0);
document.getElementsByTagName('body')[0].appendChild(canvas);
}
window.addEventListener('DOMContentLoaded', ready, false);