JSFiddle - React, Tailwind, and code Playground

by steveukx

HTML

<canvas style="border: 1px solid black;" id="canvas"></canvas>

JavaScript

var img = new Image
  , start = new Date;

img.onerror = function(err){
  throw err;
};

img.onload = function(){

  var width = img.width / 2 
    , height = img.height / 2
    , canvas = document.getElementById('canvas')
    , ctx = canvas.getContext('2d');

  canvas.width = img.width;
  canvas.height = img.height;
    
    alert([width, height]);
  ctx.drawImage(img, width / 2, height / 2, width, height);

};

img.src = 'http://www.google.co.uk/logos/2012/steno12-sr.png';