-
-
Save ncl0w/2b3706135d2755bfc3e4d75f688d4061 to your computer and use it in GitHub Desktop.
Croppie Angular Directive for a simple image cropping. https://lingohub.com/blog/2016/03/comparison-angularjs-directives-image-cropping-uploading/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use Croppie for a simple image cropping. | |
* @see https://github.com/Foliotek/Croppie | |
* @example | |
* <lh-croppie src="cropped.source" ng-model="cropped.image"></lh-croppie> | |
*/ | |
angular.module('lingohubApp').directive('lhCroppie', function () { | |
return { | |
restrict: 'E', | |
scope: { | |
src: '=', | |
ngModel: '=' | |
}, | |
link: function (scope, element, attrs) { | |
if(!scope.src) { return; } | |
var c = new Croppie(element[0], { | |
viewport: { | |
width: 200, | |
height: 200 | |
}, | |
update: function () { | |
c.result('canvas').then(function(img) { | |
scope.$apply(function () { | |
scope.ngModel = img; | |
}); | |
}); | |
} | |
}); | |
// bind an image to croppie | |
c.bind({ | |
url: scope.src | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment