Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ I'm attempting to make a self-contained AngularJS Directive which will allow you
* result (bound string) - the variable which will have the resulting data uri bound to it
* result-blob (bound Blob) - the variable which will have the resulting data as a Blob object
* crop (bound boolean) - scope variable that must be set to true when the image is ready to be cropped
* result-format - setting the result file format if different from default "image/png", optional

### Example markup
```html
Expand All @@ -43,6 +44,7 @@ I'm attempting to make a self-contained AngularJS Directive which will allow you
src="imgSrc"
data-result="result"
data-result-blob="resultBlob"
data-result-format="image/jpeg"
crop="initCrop"
padding="250"
max-size="1024"
Expand Down
14 changes: 8 additions & 6 deletions image-crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@
result: '=',
step: '=',
padding: '@',
maxSize: '@'
maxSize: '@',
resultFormat: '@'
},
link: function (scope, element, attributes) {

Expand All @@ -786,6 +787,7 @@
scope.shape = scope.shape || 'circle';
scope.width = parseInt(scope.width, 10) || 300;
scope.height = parseInt(scope.height, 10) || 300;
scope.resultFormat = scope.resultFormat || 'image/png';

scope.canvasWidth = scope.width + padding;
scope.canvasHeight = scope.height + padding;
Expand Down Expand Up @@ -1183,16 +1185,16 @@

$elm.getElementsByClassName('image-crop-section-final')[0].appendChild(tempCanvas);

var dataUrl = tempCanvas.toDataURL();
scope.result = dataUrl;
var dataUrl = tempCanvas.toDataURL(scope.resultFormat);

scope.result = dataUrl;
scope.resultBlob = dataURItoBlob(dataUrl);

scope.$apply();
};

scope.doCrop = function() {
scope.croppedDataUri = $canvas.toDataURL();
scope.croppedDataUri = $canvas.toDataURL(scope.resultFormat);
scope.step = 3;
};

Expand Down Expand Up @@ -1341,4 +1343,4 @@
});


})();
})();