diff --git a/README.md b/README.md index 3737809..4fd2744 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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" diff --git a/image-crop.js b/image-crop.js index 960d088..4ddc4f6 100644 --- a/image-crop.js +++ b/image-crop.js @@ -775,7 +775,8 @@ result: '=', step: '=', padding: '@', - maxSize: '@' + maxSize: '@', + resultFormat: '@' }, link: function (scope, element, attributes) { @@ -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; @@ -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; }; @@ -1341,4 +1343,4 @@ }); -})(); \ No newline at end of file +})();