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
Copy file name to clipboardExpand all lines: docs/api-resize.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,18 +21,22 @@ When using a **fit** of `cover` or `contain`, the default **position** is `centr
21
21
22
22
Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
23
23
24
-
The experimental strategy-based approach resizes so one dimension is at its target length
24
+
The strategy-based approach initially resizes so one dimension is at its target length
25
25
then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
26
26
-`entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
27
27
-`attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
28
28
29
-
Possible interpolation kernels are:
29
+
Possible downsizing kernels are:
30
30
-`nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
31
+
-`linear`: Use a [triangle filter](https://en.wikipedia.org/wiki/Triangular_function).
31
32
-`cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
32
33
-`mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
33
34
-`lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
34
35
-`lanczos3`: Use a Lanczos kernel with `a=3` (the default).
35
36
37
+
When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.
38
+
Downsampling kernels without a matching upsampling interpolator map to `cubic`.
39
+
36
40
Only one resize can occur per pipeline.
37
41
Previous calls to `resize` in the same pipeline will be ignored.
38
42
@@ -52,7 +56,7 @@ Previous calls to `resize` in the same pipeline will be ignored.
52
56
|[options.fit]| <code>String</code> | <code>'cover'</code> | How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`. |
53
57
|[options.position]| <code>String</code> | <code>'centre'</code> | A position, gravity or strategy to use when `fit` is `cover` or `contain`. |
54
58
|[options.background]| <code>String</code> \| <code>Object</code> | <code>{r: 0, g: 0, b: 0, alpha: 1}</code> | background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency. |
55
-
|[options.kernel]| <code>String</code> | <code>'lanczos3'</code> | The kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load. |
59
+
|[options.kernel]| <code>String</code> | <code>'lanczos3'</code> | The kernel to use for image reduction and the inferred interpolator to use for upsampling. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load. |
56
60
|[options.withoutEnlargement]| <code>Boolean</code> | <code>false</code> | Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions. |
57
61
|[options.withoutReduction]| <code>Boolean</code> | <code>false</code> | Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions. |
58
62
|[options.fastShrinkOnLoad]| <code>Boolean</code> | <code>true</code> | Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension. |
Copy file name to clipboardExpand all lines: lib/resize.js
+8-3Lines changed: 8 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,7 @@ const strategy = {
68
68
*/
69
69
constkernel={
70
70
nearest: 'nearest',
71
+
linear: 'linear',
71
72
cubic: 'cubic',
72
73
mitchell: 'mitchell',
73
74
lanczos2: 'lanczos2',
@@ -135,18 +136,22 @@ function isResizeExpected (options) {
135
136
*
136
137
* Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
137
138
*
138
-
* The experimental strategy-based approach resizes so one dimension is at its target length
139
+
* The strategy-based approach initially resizes so one dimension is at its target length
139
140
* then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
140
141
* - `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
141
142
* - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
142
143
*
143
-
* Possible interpolation kernels are:
144
+
* Possible downsizing kernels are:
144
145
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
146
+
* - `linear`: Use a [triangle filter](https://en.wikipedia.org/wiki/Triangular_function).
145
147
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
146
148
* - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
147
149
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
148
150
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
149
151
*
152
+
* When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.
153
+
* Downsampling kernels without a matching upsampling interpolator map to `cubic`.
154
+
*
150
155
* Only one resize can occur per pipeline.
151
156
* Previous calls to `resize` in the same pipeline will be ignored.
152
157
*
@@ -239,7 +244,7 @@ function isResizeExpected (options) {
239
244
* @param {String} [options.fit='cover'] - How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`.
240
245
* @param {String} [options.position='centre'] - A position, gravity or strategy to use when `fit` is `cover` or `contain`.
241
246
* @param {String|Object} [options.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
242
-
* @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.
247
+
* @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction and the inferred interpolator to use for upsampling. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.
243
248
* @param {Boolean} [options.withoutEnlargement=false] - Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions.
244
249
* @param {Boolean} [options.withoutReduction=false] - Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions.
245
250
* @param {Boolean} [options.fastShrinkOnLoad=true] - Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension.
0 commit comments