Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
fix(api.zoom): Fix & Update api.zoom() to reflect more intent
Browse files Browse the repository at this point in the history
Change api.zoom() to api.zoomIn() & api.zoomOut(). Zoom factor is automatically calculated 😎

Closes #25
  • Loading branch information
bcabanes committed Mar 1, 2016
1 parent df3dfb4 commit 68ab785
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -91,7 +91,7 @@ Angular image cropper comes with some options to simplify your development:
* `image-url` _string_ Source image that will be cropped, can be an URL or base64
* `width` _string_ Width of the cropped image
* `height` _string_ Height of the cropped image
* `zoom-step` _string_ Zoom step, must be `0 < zoomStep < 1` (0.1 is 10%)
* `zoom-step` _string_ Zoom step
* `fit-on-init` _boolean_ Fit the image on cropper initialization (keep the ratio)
* `center-on-init` _boolean_ Center the image on cropper initialization
* `show-controls` _boolean_ Display or not the control buttons (`true` by default)
Expand Down Expand Up @@ -122,7 +122,8 @@ Angular image cropper gives you access to the api, you can see an example [here]
```javascript
// Cropper API available when image is ready.
vm.getCropperApi = function(api) {
api.zoom(3);
api.zoomIn(3);
api.zoomOut(2);
api.rotate(270);
api.fit();
vm.resultImage = api.crop();
Expand All @@ -131,7 +132,8 @@ vm.getCropperApi = function(api) {
* `crop` _function_ return the cropped image in `base64`
* `fit` _function_ fit the image to the wrapper dimensions (keep the ratio)
* `rotate` _function_ Apply the rotation with degrees given, should be a modulo of 90 (90, 180, 270, 360), can be negative
* `zoom` _function_ Apply the zoom given, can be negative (fit the image if zoomOut factor is too high)
* `zoomIn` _function_ Apply the zoomIn given
* `zoomOut` _function_ Apply the zoomOut given
* `remove` _function_ Remove the cropper

## License
Expand Down
11 changes: 6 additions & 5 deletions dev/app/app.js
Expand Up @@ -13,7 +13,7 @@ angular
var vm = this;

// Some cropper options.
vm.imageUrl = 'assets/images/unsplash_' + getRandomInt(1,7) + '.jpg';
vm.imageUrl = 'assets/images/unsplash_' + getRandomInt(1, 1) + '.jpg';
vm.showControls = true;
vm.fit = false;

Expand All @@ -32,10 +32,11 @@ angular
};

// Cropper API available when image is ready.
//vm.cropperApi = function(cropperApi) {
// cropperApi.zoom(3);
// cropperApi.rotate(270);
// cropperApi.fit();
//vm.cropperApi = functigit staon(cropperApi) {
//cropperApi.zoomOut(10);
//cropperApi.zoomIn(20);
//cropperApi.rotate(270);
//cropperApi.fit();
// vm.resultImage = cropperApi.crop();
// $scope.$apply(); // Apply the changes.
//};
Expand Down
10 changes: 7 additions & 3 deletions src/imageCropper.js
Expand Up @@ -65,7 +65,8 @@ function Cropper(options) {
crop: this.cropImage.bind(this),
fit: this.applyFit.bind(this),
rotate: this.applyRotation.bind(this),
zoom: this.applyZoom.bind(this),
zoomIn: this.applyZoomIn.bind(this),
zoomOut: this.applyZoomOut.bind(this),
remove: this.remove.bind(this)
};

Expand Down Expand Up @@ -133,8 +134,11 @@ Cropper.prototype.applyRotation = function(degree) {
this.rotateImage(degree);
};

Cropper.prototype.applyZoom = function(zoom) {
this.zoomImage(zoom);
Cropper.prototype.applyZoomIn = function(zoom) {
this.zoomImage(1 + parseFloat(zoom));
};
Cropper.prototype.applyZoomOut = function(zoom) {
this.zoomImage(1 / ( 1 + parseFloat(zoom)));
};

Cropper.prototype.applyFit = function() {
Expand Down
4 changes: 2 additions & 2 deletions src/imageCropperDirective.test.js
Expand Up @@ -60,7 +60,7 @@ module.exports = function(angular) {
$scope = $rootScope.$new();

$scope.getCropperApi = function(api) {
api.zoom(3);
api.zoomIn(3);
api.rotate(270);
api.fit();
var image = api.crop();
Expand All @@ -81,7 +81,7 @@ module.exports = function(angular) {

$scope.getCropperApi = function(api) {
expect(function() {
api.zoom(3);
api.zoomIn(3);
api.rotate(25);
}).to.throw(Error, /Support only multiple of 90° for rotation./gi);
done();
Expand Down

0 comments on commit 68ab785

Please sign in to comment.