Skip to content

Instantly share code, notes, and snippets.

@ncl0w
Forked from bettysteger/croppieDrct.js
Created March 6, 2017 18:00
Show Gist options
  • Save ncl0w/2b3706135d2755bfc3e4d75f688d4061 to your computer and use it in GitHub Desktop.
Save ncl0w/2b3706135d2755bfc3e4d75f688d4061 to your computer and use it in GitHub Desktop.
/**
* 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