canvas image resize

by firegroove

HTML

<!-- <img src="http://i.imgur.com/SHo6Fub.jpg" width="300" height="234">

 -->

<img id="imagem" src="https://assets.codepen.io/1712301/7+COLORS+COMPARE+3%2B%2B%2B%2B%2B%2B.png?width=480" />

JavaScript

img = new Image();
img.src = document.getElementById("imagem").src

img.onload = function(){
  var canvas = document.createElement('canvas');
    var ctx = canvas.getContext('2d');
    canvas.width=300
    canvas.height=234
    ctx.drawImage(img, 0, 0, 300, 234);
    document.body.appendChild(canvas);
};