Fix #1041 Keep video aspect ratio when extracting thumbnail using canva

This commit is contained in:
Nicolas Le Goff
2013-03-20 18:58:09 +01:00
parent d158ef3ab5
commit 1a0753ea8f
4 changed files with 53 additions and 11 deletions

View File

@@ -6,12 +6,20 @@
*****************/
var Canva = function(domCanva){
this.domCanva = domCanva;
}
};
Canva.prototype = {
resize : function(elementDomNode){
var h = elementDomNode.getHeight();
var w = elementDomNode.getWidth();
var maxH = elementDomNode.getHeight();
var h = Math.round(w * (1 / elementDomNode.getAspectRatio()));
if (h > maxH) {
var h = maxH;
var w = Math.round(h * elementDomNode.getAspectRatio());
}
this.domCanva.setAttribute("width", w);
this.domCanva.setAttribute("height", h);
@@ -20,7 +28,7 @@
},
getContext2d : function(){
if (this.domCanva.getContext == undefined)
if (this.domCanva.getContext === undefined)
{
return G_vmlCanvasManager
.initElement(this.domCanva)
@@ -94,6 +102,7 @@
var Video = function(domElement){
Image.call(this, domElement);
this.aspectRatio = domElement.getAttribute('data-ratio') || 1;
};
Video.prototype = new Image();
@@ -101,6 +110,9 @@
Video.prototype.getCurrentTime = function(){
return Math.floor(this.domElement.currentTime);
};
Video.prototype.getAspectRatio = function(){
return this.aspectRatio;
};
/******************
* Cache Object
@@ -148,7 +160,7 @@
this.timestamp = date.getTime();
this.dataURI = canva.extractImage();
this.videoTime = video.getCurrentTime();
}
};
ScreenShot.prototype = {
getId:function(){