Skip to content

Instantly share code, notes, and snippets.

@bettysteger
Last active July 15, 2018 08:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bettysteger/25c7594288c9b102a951 to your computer and use it in GitHub Desktop.
Save bettysteger/25c7594288c9b102a951 to your computer and use it in GitHub Desktop.
Croppie Angular Directive for a simple image cropping. Directive => Component: https://github.com/lpsBetty/angular-croppie
/**
* 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
});
}
};
});
@RobbertWolfs
Copy link

Any example using this directive?

@pyccki
Copy link

pyccki commented Dec 20, 2016

yes,
Any examples would be appreciated !!!

@bettysteger
Copy link
Author

I made a Angular 1.5+ component: https://github.com/lpsBetty/angular-croppie
there is an example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment