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

Commit 68ab785

Browse files
author
bcabanes
committed
fix(api.zoom): Fix & Update api.zoom() to reflect more intent
Change api.zoom() to api.zoomIn() & api.zoomOut(). Zoom factor is automatically calculated 😎 Closes #25
1 parent df3dfb4 commit 68ab785

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Angular image cropper comes with some options to simplify your development:
9191
* `image-url` _string_ Source image that will be cropped, can be an URL or base64
9292
* `width` _string_ Width of the cropped image
9393
* `height` _string_ Height of the cropped image
94-
* `zoom-step` _string_ Zoom step, must be `0 < zoomStep < 1` (0.1 is 10%)
94+
* `zoom-step` _string_ Zoom step
9595
* `fit-on-init` _boolean_ Fit the image on cropper initialization (keep the ratio)
9696
* `center-on-init` _boolean_ Center the image on cropper initialization
9797
* `show-controls` _boolean_ Display or not the control buttons (`true` by default)
@@ -122,7 +122,8 @@ Angular image cropper gives you access to the api, you can see an example [here]
122122
```javascript
123123
// Cropper API available when image is ready.
124124
vm.getCropperApi = function(api) {
125-
api.zoom(3);
125+
api.zoomIn(3);
126+
api.zoomOut(2);
126127
api.rotate(270);
127128
api.fit();
128129
vm.resultImage = api.crop();
@@ -131,7 +132,8 @@ vm.getCropperApi = function(api) {
131132
* `crop` _function_ return the cropped image in `base64`
132133
* `fit` _function_ fit the image to the wrapper dimensions (keep the ratio)
133134
* `rotate` _function_ Apply the rotation with degrees given, should be a modulo of 90 (90, 180, 270, 360), can be negative
134-
* `zoom` _function_ Apply the zoom given, can be negative (fit the image if zoomOut factor is too high)
135+
* `zoomIn` _function_ Apply the zoomIn given
136+
* `zoomOut` _function_ Apply the zoomOut given
135137
* `remove` _function_ Remove the cropper
136138

137139
## License

dev/app/app.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ angular
1313
var vm = this;
1414

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

@@ -32,10 +32,11 @@ angular
3232
};
3333

3434
// Cropper API available when image is ready.
35-
//vm.cropperApi = function(cropperApi) {
36-
// cropperApi.zoom(3);
37-
// cropperApi.rotate(270);
38-
// cropperApi.fit();
35+
//vm.cropperApi = functigit staon(cropperApi) {
36+
//cropperApi.zoomOut(10);
37+
//cropperApi.zoomIn(20);
38+
//cropperApi.rotate(270);
39+
//cropperApi.fit();
3940
// vm.resultImage = cropperApi.crop();
4041
// $scope.$apply(); // Apply the changes.
4142
//};

src/imageCropper.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function Cropper(options) {
6565
crop: this.cropImage.bind(this),
6666
fit: this.applyFit.bind(this),
6767
rotate: this.applyRotation.bind(this),
68-
zoom: this.applyZoom.bind(this),
68+
zoomIn: this.applyZoomIn.bind(this),
69+
zoomOut: this.applyZoomOut.bind(this),
6970
remove: this.remove.bind(this)
7071
};
7172

@@ -133,8 +134,11 @@ Cropper.prototype.applyRotation = function(degree) {
133134
this.rotateImage(degree);
134135
};
135136

136-
Cropper.prototype.applyZoom = function(zoom) {
137-
this.zoomImage(zoom);
137+
Cropper.prototype.applyZoomIn = function(zoom) {
138+
this.zoomImage(1 + parseFloat(zoom));
139+
};
140+
Cropper.prototype.applyZoomOut = function(zoom) {
141+
this.zoomImage(1 / ( 1 + parseFloat(zoom)));
138142
};
139143

140144
Cropper.prototype.applyFit = function() {

src/imageCropperDirective.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = function(angular) {
6060
$scope = $rootScope.$new();
6161

6262
$scope.getCropperApi = function(api) {
63-
api.zoom(3);
63+
api.zoomIn(3);
6464
api.rotate(270);
6565
api.fit();
6666
var image = api.crop();
@@ -81,7 +81,7 @@ module.exports = function(angular) {
8181

8282
$scope.getCropperApi = function(api) {
8383
expect(function() {
84-
api.zoom(3);
84+
api.zoomIn(3);
8585
api.rotate(25);
8686
}).to.throw(Error, /Support only multiple of 90° for rotation./gi);
8787
done();

0 commit comments

Comments
 (0)