I am trying to add size limits on image resize using KineticJS library. HTML5 Canvas Tutorial provides the method to resize the image: http://www.html5canvastutorials.com/labs/html5-canvas-drag-and-drop-resize-and-invert-images/
But I want the user not to be able to resize the image to less than 50px x 50px or greater than 200 x 200. I have tried a lot manage the controls by following code. But it shows very strange results
dragBoundFunc: function(pos) {
var newX = '';
var image_width = group.get(".darthVaderImg")[0].getWidth();
var image_height = group.get(".darthVaderImg")[0].getHeight();
var image_position = group.get(".darthVaderImg")[0].getPosition();
if((image_width>50 && image_width< 200) ){
newX = pos.x;
}else{
newX = image_position.x+image_width+80;
}
if((image_height>50 && image_height< 200) ){
newY = pos.y;
}else{
newY = image_position.y+100;
}
return {
x: newX ,
y: newY,
};
}
Any example or idea that how I can do it