mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-19 03:42:52 +08:00
CB-9591 Retaining aspect ratio when resizing
This commit is contained in:
parent
ee5cfe89a5
commit
cad9ab0419
@ -93,8 +93,10 @@ function resizeImage(successCallback, errorCallback, file, targetWidth, targetHe
|
|||||||
var image = new Image();
|
var image = new Image();
|
||||||
image.src = imageData;
|
image.src = imageData;
|
||||||
image.onload = function() {
|
image.onload = function() {
|
||||||
var imageWidth = targetWidth,
|
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
|
||||||
imageHeight = targetHeight;
|
var imageWidth = ratio * this.width;
|
||||||
|
var imageHeight = ratio * this.height;
|
||||||
|
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
var storageFileName;
|
var storageFileName;
|
||||||
|
|
||||||
@ -134,8 +136,9 @@ function resizeImageBase64(successCallback, errorCallback, file, targetWidth, ta
|
|||||||
image.src = imageData;
|
image.src = imageData;
|
||||||
|
|
||||||
image.onload = function() {
|
image.onload = function() {
|
||||||
var imageWidth = targetWidth,
|
var ratio = Math.min(targetWidth / this.width, targetHeight / this.height);
|
||||||
imageHeight = targetHeight;
|
var imageWidth = ratio * this.width;
|
||||||
|
var imageHeight = ratio * this.height;
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
|
||||||
canvas.width = imageWidth;
|
canvas.width = imageWidth;
|
||||||
|
Loading…
Reference in New Issue
Block a user