cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mura...@apache.org
Subject cordova-plugin-camera git commit: CB-9591 Retaining aspect ratio when resizing
Date Tue, 01 Sep 2015 17:52:00 GMT
Repository: cordova-plugin-camera
Updated Branches:
  refs/heads/master ee5cfe89a -> cad9ab041


CB-9591 Retaining aspect ratio when resizing


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/cad9ab04
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/cad9ab04
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/cad9ab04

Branch: refs/heads/master
Commit: cad9ab0419ec3c90f0c052483177952d364a353d
Parents: ee5cfe8
Author: Jakub Navrátil <navrc.kuba@gmail.com>
Authored: Thu Aug 27 23:32:50 2015 +0200
Committer: Murat Sutunc <sutunc@gmail.com>
Committed: Tue Sep 1 10:49:12 2015 -0700

----------------------------------------------------------------------
 src/windows/CameraProxy.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/cad9ab04/src/windows/CameraProxy.js
----------------------------------------------------------------------
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;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message