andrefarzat / ng-jcrop

Angular directive to jCrop jQuery plugin
GNU General Public License v2.0
101 stars 39 forks source link

coords issue for image width/height less than maxwidth/maxheight #18

Closed bkasodariya closed 9 years ago

bkasodariya commented 9 years ago

Hi André,

Tried to crop different size images. It returns wrong coordinate when image width is less than maxwidth. to fix that, added extra width check in getShrinkRatio function.

$scope.getShrinkRatio = function(){
        var img = $('<img>').attr('src', $scope.mainImg[0].src)[0];
        var widthShrinkRatio = img.width / ngJcropConfig.jcrop.maxWidth,
            heightShrinkRatio = img.height / ngJcropConfig.jcrop.maxHeight,
            widthConstraining = img.width > ngJcropConfig.jcrop.maxWidth && widthShrinkRatio > heightShrinkRatio;
        //fix   
        if(ngJcropConfig.jcrop.maxWidth>img.width || ngJcropConfig.jcrop.maxHeight>img.height){
            return 1;
        }

        if(widthConstraining) {
            return widthShrinkRatio;
        } else {
            return heightShrinkRatio;
        }
    };