diff --git a/dist/image-editor.js b/dist/image-editor.js index 3780c88..df03a69 100644 --- a/dist/image-editor.js +++ b/dist/image-editor.js @@ -1363,6 +1363,20 @@ function ImageEditor(canvasId, args) { 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 {object} defaultValue diff --git a/src/ImageEditor.js b/src/ImageEditor.js index 8ec25d4..85cf182 100644 --- a/src/ImageEditor.js +++ b/src/ImageEditor.js @@ -125,6 +125,20 @@ function ImageEditor(canvasId, args) { 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 {object} defaultValue