Add method for getting crop data

editor.canvas.getImage().transformation.getData() get an object
with information about the image, it's width, height, if it's
mirrored and so on.
This commit is contained in:
Rikard Bartholf
2017-05-18 11:45:43 +02:00
parent 0c34480bd1
commit 2acdcafe09
3 changed files with 54 additions and 1 deletions
@@ -34,6 +34,13 @@ function FrameHandler(viewport) {
init();
/**
* @return {String}
*/
this.getFrameType = function () {
return _frameType;
};
this.setVisible = function (isVisible) {
isVisible = typeof isVisible === 'undefined' ? true : !!isVisible;
@@ -1,7 +1,50 @@
'use strict';
function ImageTransformationHandler(img) {
var _transformations = {};
var _transformations = {
mirror: false
};
/**
* Gets information about how the cropped image is dragged
* @return {Object}
*/
this.getCropData = function () {
var viewportBounds = img.canvas.getViewport().getBounds();
var dragAxis = img.canvas.getViewport().getData().axis;
return {
x: dragAxis === 'h' ? (viewportBounds.left - img.left) / img.width : 0,
y: dragAxis === 'v' ? (viewportBounds.top - img.top) / img.height : 0,
};
};
/**
* Gets an object containing applied transformations for the Image and also
* how it is cropped and dragged.
* @return {Object}
*/
this.getData = function () {
var viewportData = img.canvas.getViewport().getData();
var returnValue = $.extend(
{},
_transformations,
{
width: viewportData.dim.width,
height: viewportData.dim.height,
},
this.getCropData()
);
if (img.canvas.__type === 'canvas') {
var frameHandler = img.canvas.getViewport().getFrameHandler();
returnValue.edge = frameHandler.getFrameType();
returnValue.framed = returnValue.edge !== 'none';
}
return returnValue;
};
/**
* @param {String} name
@@ -50,6 +50,9 @@ function ExtendFabricFunctionality() {
height: bounds.height - this.strokeWidth * 2
};
returnValue.right = returnValue.left + returnValue.width;
returnValue.bottom = returnValue.top + returnValue.height;
returnValue.min = {
left: returnValue.left,
top: returnValue.top