CB-9591 Retaining aspect ratio when resizing

This commit is contained in:
Jakub Navrátil 2015-08-27 23:32:50 +02:00 committed by Murat Sutunc
parent ee5cfe89a5
commit cad9ab0419

View File

@ -93,8 +93,10 @@ function resizeImage(successCallback, errorCallback, file, targetWidth, targetHe
var image = new Image();
image.src = imageData;
image.onload = function() {
var imageWidth = targetWidth,
imageHeight = targetHeight;
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width;
var imageHeight = ratio * this.height;
var canvas = document.createElement('canvas');
var storageFileName;
@ -134,8 +136,9 @@ function resizeImageBase64(successCallback, errorCallback, file, targetWidth, ta
image.src = imageData;
image.onload = function() {
var imageWidth = targetWidth,
imageHeight = targetHeight;
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
var imageWidth = ratio * this.width;
var imageHeight = ratio * this.height;
var canvas = document.createElement('canvas');
canvas.width = imageWidth;