@@ -28,32 +28,32 @@ function image(src) {
30function fittedImage(w,h,src) {
30function fittedImage(w,h,src) {
31− var canvas = newElement('canvas');
31+ var e = newElement('div');
32− canvas.style.display = "block";
33− canvas.style.width = w + 'px';
32+ e.style.width = w + 'px';
34− canvas.style.height = h + 'px';
33+ e.style.height = h + 'px';
35− canvas.width = w;
34+ e.style.position = "relative";
36− canvas.height = h;
35+ e.style.overflow = "hidden";
37− canvas.innerHTML = "Your browser does not support the canvas element.";
39 var img = newElement('img');
37 var img = newElement('img');
40 img.onload = function() {
38 img.onload = function() {
41− if (canvas.getContext) {
39+ img.style.position = 'absolute';
42− var ctx = canvas.getContext('2d');
40+ img.style.margin = 'auto';
43− var sx = 0, sy = 0, sWidth = this.width, sHeight = this.height;
41+
44− if (w / h > this.width / this.height) {
43+ if (w / h > this.width / this.height) {
45− sHeight = this.width * h / w;
44+ sh = Math.round(this.height * w / this.width);
46− sy = (this.height - sHeight) / 2;
48− sWidth = this.height * w / h;
46+ sw = Math.round(this.width * h / this.height);
49− sx = (this.width - sWidth) / 2;
51− ctx.drawImage(img, sx, sy, sWidth, sHeight,
52− 0,0, canvas.width, canvas.height);
48+ img.style.width = sw + 'px';
49+ img.style.height = sh + 'px';
50+ img.style.left = ((w - sw) / 2) + 'px';
51+ img.style.top = ((h - sh) / 2) + 'px';
55 img.src = src;
53 img.src = src;
56− return canvas;
56+ return e;
59var video = function(src) {
59var video = function(src) {