From cad9ab0419ec3c90f0c052483177952d364a353d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Navr=C3=A1til?= Date: Thu, 27 Aug 2015 23:32:50 +0200 Subject: [PATCH] CB-9591 Retaining aspect ratio when resizing --- src/windows/CameraProxy.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js index 5ad9475..505d3d8 100644 --- a/src/windows/CameraProxy.js +++ b/src/windows/CameraProxy.js @@ -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;