P5-2706 add getCropRatio function
This commit is contained in:
Vendored
+14
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user