P5-2706 add getCropRatio function

This commit is contained in:
Anders Gustafsson
2018-06-12 11:02:54 +02:00
parent 38f4a10ed1
commit 37481d2fcd
2 changed files with 28 additions and 0 deletions
+14
View File
@@ -1363,6 +1363,20 @@ function ImageEditor(canvasId, args) {
return this; return this;
}; };
this.getCropRatio = function () {
var image = _canvas.getImage();
var cropData = _canvas.getImageData().getCropData();
if (!cropData) {
return false;
}
var scaledImageWidth = image.width * image.scaleX;
var scaledImageHeight = image.height * image.scaleY;
var ratioWidth = Math.round(cropData.viewportWidth / scaledImageWidth * 100) / 100;
var ratioHeight = Math.round(cropData.viewportHeight / scaledImageHeight * 100) / 100;
return {width: ratioWidth, height: ratioHeight};
};
/** /**
* @param {string|object} key * @param {string|object} key
* @param {object} defaultValue * @param {object} defaultValue
+14
View File
@@ -125,6 +125,20 @@ function ImageEditor(canvasId, args) {
return this; return this;
}; };
this.getCropRatio = function () {
var image = _canvas.getImage();
var cropData = _canvas.getImageData().getCropData();
if (!cropData) {
return false;
}
var scaledImageWidth = image.width * image.scaleX;
var scaledImageHeight = image.height * image.scaleY;
var ratioWidth = Math.round(cropData.viewportWidth / scaledImageWidth * 100) / 100;
var ratioHeight = Math.round(cropData.viewportHeight / scaledImageHeight * 100) / 100;
return {width: ratioWidth, height: ratioHeight};
};
/** /**
* @param {string|object} key * @param {string|object} key
* @param {object} defaultValue * @param {object} defaultValue