JSFiddle - React, Tailwind, and code Playground
HTML
<div class="one">
<canvas id="myCanvas" width="578" height="400"</canvas>
</div>
CSS
body {
margin: 0px;
padding: 0px;
}
.one {
background-color:blue;
width:600px;
height:300px;
}
#myCanvas {position:relative;}
JavaScript
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var imageObj = new Image();
imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/darth-vader.jpg';
imageObj.onload = function() {
//context.drawImage(imageObj, 69, 50);
var width = 200;
var height = imageObj.height * (width/imageObj.width);
canvas.width=width;
canvas.height=height;
context.drawImage(imageObj, 0, 0, width, height);
};