You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Image: [https://www.flickr.com/photos/endogamia/5682480447/](https://www.flickr.com/photos/endogamia/5682480447) by N. Feans
7
8
8
9
## Demos
9
-
*[Test Suite](http://29a.ch/sandbox/2014/smartcrop/examples/testsuite.html), contains over 100 images, **heavy**
10
-
*[Test Bed](http://29a.ch/sandbox/2014/smartcrop/examples/testbed.html), allows you to upload your own images
10
+
*[Test Suite](http://29a.ch/sandbox/2014/smartcrop/examples/testsuite.html), contains over 100 images, **heavy**.
11
+
*[Test Bed](http://29a.ch/sandbox/2014/smartcrop/examples/testbed.html), allows you to test smartcrop with your own images.
11
12
*[Photo transitions](http://29a.ch/sandbox/2014/smartcrop/examples/slideshow.html), automatically creates Ken Burns transitions for a slide show.
12
13
13
14
## Algorithm Overview
@@ -16,6 +17,7 @@ Smartcrop.js works using fairly dumb image processing. In short:
16
17
1. Find edges using laplace
17
18
1. Find regions with a color like skin
18
19
1. Find regions high in saturation
20
+
1. Boost regions as specified by options (for example detected faces)
19
21
1. Generate a set of candidate crops using a sliding window
20
22
1. Rank them using an importance function to focus the detail in the center
21
23
and avoid it in the edges.
@@ -37,26 +39,28 @@ Output:
37
39
```npm install smartcrop```
38
40
or
39
41
```bower install smartcrop```
40
-
or just download [smartcrop.js](https://raw.githubusercontent.com/jwagner/smartcrop.js/master/smartcrop.js) from the git repo.
42
+
or just download [smartcrop.js](https://raw.githubusercontent.com/jwagner/smartcrop.js/master/smartcrop.js) from the git repository.
41
43
42
44
Smarcrop requires support for [Promises](http://caniuse.com/#feat=promises),
43
-
use a [polyfill](https://github.com/taylorhakes/promise-polyfill) for unsupported browsers or set `smartcrop.Promise` to your promise implementation
45
+
use a [polyfill](https://github.com/taylorhakes/promise-polyfill) for unsupported browsers or set `smartcrop.Promise` to your favorite promise implementation
44
46
(I recommend [bluebird](http://bluebirdjs.com/)).
45
47
48
+
## Command Line Interface
49
+
The [smartcrop-cli](https://github.com/jwagner/smartcrop-cli) offers command line interface to smartcrop.js.
46
50
47
-
## CLI / Node.js
48
-
The [smartcrop-cli](https://github.com/jwagner/smartcrop-cli) offers command line interface to smartcrop.js. It also serves as an example on how to use smartcrop
49
-
from node.
51
+
## Node
52
+
You can use smartcrop from nodejs via either [smartcrop-gm](https://github.com/jwagner/smartcrop-gm) (which is using image magick via gm) or [smartcrop-sharp](https://github.com/jwagner/smartcrop-sharp) (which is using libvips via sharp).
53
+
The [smartcrop-cli](https://github.com/jwagner/smartcrop-cli) can be used as an example of using smartcrop from node.
50
54
51
-
## Module Formats
55
+
## Supported Module Formats
52
56
53
-
*common js
54
-
*amd
57
+
*CommonJS
58
+
*AMD
55
59
* global export / window
56
60
57
61
## Supported Browsers
58
62
59
-
See [caniuse.com/canvas](http://caniuse.com/canvas)
63
+
See [caniuse.com/canvas](http://caniuse.com/canvas).
60
64
A [polyfill](https://github.com/taylorhakes/promise-polyfill) for
61
65
[Promises](http://caniuse.com/#feat=promises) is recommended.
62
66
@@ -84,18 +88,26 @@ You may not use cross-domain images without [CORS](https://en.wikipedia.org/wiki
84
88
85
89
**height:** height of the crop you want to use.
86
90
87
-
**debug *(internal)*:**if true, cropResults will contain a debugCanvas.
91
+
**boost:**optional array of regions whose 'interestingness' you want to boost (for example faces). See [boost](#boost);
88
92
89
-
There are many more (for now undocumented) options available. Check the [source](smartcrop.js#L32) and know that they might change in the future.
93
+
**ruleOfThirds:** optional boolean if set to false it will turn off the rule of thirds composition weight.
94
+
95
+
**debug *(internal)*:** if true, cropResults will contain a debugCanvas and the complete results array.
96
+
97
+
There are many more (for now undocumented) options available.
98
+
Check the [source](smartcrop.js#L32) and be advised that they might change in the future.
90
99
91
100
### cropResult
101
+
Result of the promise returned by smartcrop.crop.
92
102
```javascript
93
103
{
94
-
topCrop: crop,
95
-
crops: [crop]
104
+
topCrop: crop
96
105
}
97
106
```
107
+
98
108
### crop
109
+
An invididual crop.
110
+
99
111
```javascript
100
112
{
101
113
x:11, // pixels from the left side
@@ -105,8 +117,22 @@ There are many more (for now undocumented) options available. Check the [source]
105
117
}
106
118
```
107
119
108
-
## Tests
120
+
### boost
121
+
Describes a region to boost. A usage example of this is to take
122
+
into account faces in the image. See [smartcrop-cli](https://github.com/jwagner/smartcrop-cli) for an example on how to integrate face detection.
109
123
124
+
```javascript
125
+
{
126
+
x:11, // pixels from the left side
127
+
y:20, // pixels from the top
128
+
width:1, // pixels
129
+
height:1, // pixels
130
+
weight:1// [0, 1]
131
+
}
132
+
```
133
+
134
+
135
+
## Tests
110
136
You can run the tests using grunt test. Alternatively you can also just run grunt (the default task) and open http://localhost:8000/test/.
111
137
The test coverage for smartcrop.js is very limited at the moment. I expect to improve this as the code matures and the concepts solidify.
112
138
@@ -128,5 +154,12 @@ In other words, it's fine to run it on one image, it's not cool to run it on an
128
154
*[smartcrop.py](https://github.com/hhatto/smartcrop.py) by [Hideo Hattori](http://www.hexacosa.net/about/)
129
155
*[smartcrop-rails](https://github.com/sadiqmmm/smartcrop-rails) smartcrop wrapped in a ruby gem by [Mohammed Sadiq](https://github.com/sadiqmmm/)
130
156
157
+
## Version history
158
+
159
+
### 1.0
160
+
Refactoring/cleanup to make it easier to use with node.js (dropping the node-canvas dependency) and enable support for boosts which can be used to do face detection.
161
+
This is a 1.0 in the semantic meaning (denoting backwards incompatible API changes).
162
+
It does not denote a finished product.
163
+
131
164
## License
132
165
Copyright (c) 2016 Jonas Wagner, licensed under the MIT License (enclosed)
0 commit comments