sharp 0.17.2 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +1 -7
- package/binding.gyp +1 -1
- package/binding.js +14 -14
- package/docs/api-colour.md +2 -2
- package/docs/api-composite.md +11 -3
- package/docs/api-constructor.md +25 -5
- package/docs/api-input.md +4 -3
- package/docs/api-operation.md +20 -17
- package/docs/api-output.md +39 -30
- package/docs/api-resize.md +9 -8
- package/docs/api-utility.md +4 -4
- package/docs/changelog.md +103 -0
- package/docs/index.md +4 -1
- package/docs/install.md +44 -14
- package/lib/channel.js +6 -6
- package/lib/colour.js +10 -10
- package/lib/composite.js +11 -6
- package/lib/constructor.js +41 -18
- package/lib/input.js +52 -24
- package/lib/is.js +9 -0
- package/lib/operation.js +41 -38
- package/lib/output.js +103 -112
- package/lib/resize.js +25 -20
- package/lib/utility.js +8 -8
- package/package.json +22 -18
- package/src/common.cc +94 -20
- package/src/common.h +30 -3
- package/src/libvips/cplusplus/VImage.cpp +110 -104
- package/src/libvips/cplusplus/vips-operators.cpp +108 -44
- package/src/metadata.cc +19 -4
- package/src/metadata.h +1 -0
- package/src/operations.cc +18 -165
- package/src/operations.h +4 -26
- package/src/pipeline.cc +201 -97
- package/src/pipeline.h +14 -0
- package/src/sharp.cc +3 -0
package/lib/output.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const util = require('util');
|
|
4
3
|
const is = require('./is');
|
|
5
4
|
const sharp = require('../build/Release/sharp.node');
|
|
6
5
|
|
|
@@ -15,11 +14,12 @@ const sharp = require('../build/Release/sharp.node');
|
|
|
15
14
|
*
|
|
16
15
|
* @param {String} fileOut - the path to write the image data to.
|
|
17
16
|
* @param {Function} [callback] - called on completion with two arguments `(err, info)`.
|
|
18
|
-
* `info` contains the output image `format`, `size` (bytes), `width`, `height
|
|
17
|
+
* `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
|
18
|
+
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
|
19
19
|
* @returns {Promise<Object>} - when no callback is provided
|
|
20
20
|
* @throws {Error} Invalid parameters
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
function toFile (fileOut, callback) {
|
|
23
23
|
if (!fileOut || fileOut.length === 0) {
|
|
24
24
|
const errOutputInvalid = new Error('Invalid output');
|
|
25
25
|
if (is.fn(callback)) {
|
|
@@ -41,25 +41,33 @@ const toFile = function toFile (fileOut, callback) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return this;
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Write output to a Buffer.
|
|
48
|
-
* JPEG, PNG, WebP, and RAW output are supported.
|
|
48
|
+
* JPEG, PNG, WebP, TIFF and RAW output are supported.
|
|
49
49
|
* By default, the format will match the input image, except GIF and SVG input which become PNG output.
|
|
50
50
|
*
|
|
51
|
-
* `callback`, if present, gets three arguments `(err,
|
|
52
|
-
* - `err` is an error
|
|
53
|
-
* - `
|
|
54
|
-
* - `info` contains the output image `format`, `size` (bytes), `width`, `height
|
|
55
|
-
*
|
|
51
|
+
* `callback`, if present, gets three arguments `(err, data, info)` where:
|
|
52
|
+
* - `err` is an error, if any.
|
|
53
|
+
* - `data` is the output image data.
|
|
54
|
+
* - `info` contains the output image `format`, `size` (bytes), `width`, `height`,
|
|
55
|
+
* `channels` and `premultiplied` (indicating if premultiplication was used).
|
|
56
|
+
* A Promise is returned when `callback` is not provided.
|
|
56
57
|
*
|
|
58
|
+
* @param {Object} [options]
|
|
59
|
+
* @param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
|
|
57
60
|
* @param {Function} [callback]
|
|
58
61
|
* @returns {Promise<Buffer>} - when no callback is provided
|
|
59
62
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
function toBuffer (options, callback) {
|
|
64
|
+
if (is.object(options)) {
|
|
65
|
+
if (is.bool(options.resolveWithObject)) {
|
|
66
|
+
this.options.resolveWithObject = options.resolveWithObject;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return this._pipeline(is.fn(options) ? options : callback);
|
|
70
|
+
}
|
|
63
71
|
|
|
64
72
|
/**
|
|
65
73
|
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
|
|
@@ -70,7 +78,7 @@ const toBuffer = function toBuffer (callback) {
|
|
|
70
78
|
* @returns {Sharp}
|
|
71
79
|
* @throws {Error} Invalid parameters
|
|
72
80
|
*/
|
|
73
|
-
|
|
81
|
+
function withMetadata (withMetadata) {
|
|
74
82
|
this.options.withMetadata = is.bool(withMetadata) ? withMetadata : true;
|
|
75
83
|
if (is.object(withMetadata)) {
|
|
76
84
|
if (is.defined(withMetadata.orientation)) {
|
|
@@ -82,7 +90,7 @@ const withMetadata = function withMetadata (withMetadata) {
|
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
return this;
|
|
85
|
-
}
|
|
93
|
+
}
|
|
86
94
|
|
|
87
95
|
/**
|
|
88
96
|
* Use these JPEG options for output image.
|
|
@@ -98,7 +106,7 @@ const withMetadata = function withMetadata (withMetadata) {
|
|
|
98
106
|
* @returns {Sharp}
|
|
99
107
|
* @throws {Error} Invalid options
|
|
100
108
|
*/
|
|
101
|
-
|
|
109
|
+
function jpeg (options) {
|
|
102
110
|
if (is.object(options)) {
|
|
103
111
|
if (is.defined(options.quality)) {
|
|
104
112
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
|
@@ -133,7 +141,7 @@ const jpeg = function jpeg (options) {
|
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
return this._updateFormatOut('jpeg', options);
|
|
136
|
-
}
|
|
144
|
+
}
|
|
137
145
|
|
|
138
146
|
/**
|
|
139
147
|
* Use these PNG options for output image.
|
|
@@ -145,7 +153,7 @@ const jpeg = function jpeg (options) {
|
|
|
145
153
|
* @returns {Sharp}
|
|
146
154
|
* @throws {Error} Invalid options
|
|
147
155
|
*/
|
|
148
|
-
|
|
156
|
+
function png (options) {
|
|
149
157
|
if (is.object(options)) {
|
|
150
158
|
if (is.defined(options.progressive)) {
|
|
151
159
|
this._setBooleanOption('pngProgressive', options.progressive);
|
|
@@ -162,7 +170,7 @@ const png = function png (options) {
|
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
172
|
return this._updateFormatOut('png', options);
|
|
165
|
-
}
|
|
173
|
+
}
|
|
166
174
|
|
|
167
175
|
/**
|
|
168
176
|
* Use these WebP options for output image.
|
|
@@ -175,7 +183,7 @@ const png = function png (options) {
|
|
|
175
183
|
* @returns {Sharp}
|
|
176
184
|
* @throws {Error} Invalid options
|
|
177
185
|
*/
|
|
178
|
-
|
|
186
|
+
function webp (options) {
|
|
179
187
|
if (is.object(options) && is.defined(options.quality)) {
|
|
180
188
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
|
181
189
|
this.options.webpQuality = options.quality;
|
|
@@ -197,17 +205,22 @@ const webp = function webp (options) {
|
|
|
197
205
|
this._setBooleanOption('webpNearLossless', options.nearLossless);
|
|
198
206
|
}
|
|
199
207
|
return this._updateFormatOut('webp', options);
|
|
200
|
-
}
|
|
208
|
+
}
|
|
201
209
|
|
|
202
210
|
/**
|
|
203
211
|
* Use these TIFF options for output image.
|
|
204
212
|
* @param {Object} [options] - output options
|
|
205
213
|
* @param {Number} [options.quality=80] - quality, integer 1-100
|
|
206
214
|
* @param {Boolean} [options.force=true] - force TIFF output, otherwise attempt to use input format
|
|
215
|
+
* @param {Boolean} [options.compression='jpeg'] - compression options: lzw, deflate, jpeg
|
|
216
|
+
* @param {Boolean} [options.predictor='none'] - compression predictor options: none, horizontal, float
|
|
217
|
+
* @param {Number} [options.xres=1.0] - horizontal resolution in pixels/mm
|
|
218
|
+
* @param {Number} [options.yres=1.0] - vertical resolution in pixels/mm
|
|
219
|
+
* @param {Boolean} [options.squash=false] - squash 8-bit images down to 1 bit
|
|
207
220
|
* @returns {Sharp}
|
|
208
221
|
* @throws {Error} Invalid options
|
|
209
222
|
*/
|
|
210
|
-
|
|
223
|
+
function tiff (options) {
|
|
211
224
|
if (is.object(options) && is.defined(options.quality)) {
|
|
212
225
|
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
|
|
213
226
|
this.options.tiffQuality = options.quality;
|
|
@@ -215,16 +228,56 @@ const tiff = function tiff (options) {
|
|
|
215
228
|
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
|
|
216
229
|
}
|
|
217
230
|
}
|
|
231
|
+
if (is.object(options) && is.defined(options.squash)) {
|
|
232
|
+
if (is.bool(options.squash)) {
|
|
233
|
+
this.options.tiffSquash = options.squash;
|
|
234
|
+
} else {
|
|
235
|
+
throw new Error('Invalid Value for squash ' + options.squash + ' Only Boolean Values allowed for options.squash.');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// resolution
|
|
239
|
+
if (is.object(options) && is.defined(options.xres)) {
|
|
240
|
+
if (is.number(options.xres)) {
|
|
241
|
+
this.options.tiffXres = options.xres;
|
|
242
|
+
} else {
|
|
243
|
+
throw new Error('Invalid Value for xres ' + options.xres + ' Only numeric values allowed for options.xres');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (is.object(options) && is.defined(options.yres)) {
|
|
247
|
+
if (is.number(options.yres)) {
|
|
248
|
+
this.options.tiffYres = options.yres;
|
|
249
|
+
} else {
|
|
250
|
+
throw new Error('Invalid Value for yres ' + options.yres + ' Only numeric values allowed for options.yres');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// compression
|
|
254
|
+
if (is.defined(options) && is.defined(options.compression)) {
|
|
255
|
+
if (is.string(options.compression) && is.inArray(options.compression, ['lzw', 'deflate', 'jpeg', 'none'])) {
|
|
256
|
+
this.options.tiffCompression = options.compression;
|
|
257
|
+
} else {
|
|
258
|
+
const message = `Invalid compression option "${options.compression}". Should be one of: lzw, deflate, jpeg, none`;
|
|
259
|
+
throw new Error(message);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// predictor
|
|
263
|
+
if (is.defined(options) && is.defined(options.predictor)) {
|
|
264
|
+
if (is.string(options.predictor) && is.inArray(options.predictor, ['none', 'horizontal', 'float'])) {
|
|
265
|
+
this.options.tiffPredictor = options.predictor;
|
|
266
|
+
} else {
|
|
267
|
+
const message = `Invalid predictor option "${options.predictor}". Should be one of: none, horizontal, float`;
|
|
268
|
+
throw new Error(message);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
218
271
|
return this._updateFormatOut('tiff', options);
|
|
219
|
-
}
|
|
272
|
+
}
|
|
220
273
|
|
|
221
274
|
/**
|
|
222
275
|
* Force output to be raw, uncompressed uint8 pixel data.
|
|
223
276
|
* @returns {Sharp}
|
|
224
277
|
*/
|
|
225
|
-
|
|
278
|
+
function raw () {
|
|
226
279
|
return this._updateFormatOut('raw');
|
|
227
|
-
}
|
|
280
|
+
}
|
|
228
281
|
|
|
229
282
|
/**
|
|
230
283
|
* Force output to a given format.
|
|
@@ -233,15 +286,16 @@ const raw = function raw () {
|
|
|
233
286
|
* @returns {Sharp}
|
|
234
287
|
* @throws {Error} unsupported format or options
|
|
235
288
|
*/
|
|
236
|
-
|
|
289
|
+
function toFormat (format, options) {
|
|
237
290
|
if (is.object(format) && is.string(format.id)) {
|
|
238
291
|
format = format.id;
|
|
239
292
|
}
|
|
293
|
+
if (format === 'jpg') format = 'jpeg';
|
|
240
294
|
if (!is.inArray(format, ['jpeg', 'png', 'webp', 'tiff', 'raw'])) {
|
|
241
295
|
throw new Error('Unsupported output format ' + format);
|
|
242
296
|
}
|
|
243
297
|
return this[format](options);
|
|
244
|
-
}
|
|
298
|
+
}
|
|
245
299
|
|
|
246
300
|
/**
|
|
247
301
|
* Use tile-based deep zoom (image pyramid) output.
|
|
@@ -267,7 +321,7 @@ const toFormat = function toFormat (format, options) {
|
|
|
267
321
|
* @returns {Sharp}
|
|
268
322
|
* @throws {Error} Invalid parameters
|
|
269
323
|
*/
|
|
270
|
-
|
|
324
|
+
function tile (tile) {
|
|
271
325
|
if (is.object(tile)) {
|
|
272
326
|
// Size of square tiles, in pixels
|
|
273
327
|
if (is.defined(tile.size)) {
|
|
@@ -312,7 +366,7 @@ const tile = function tile (tile) {
|
|
|
312
366
|
throw new Error('Invalid tile format ' + this.options.formatOut);
|
|
313
367
|
}
|
|
314
368
|
return this._updateFormatOut('dz');
|
|
315
|
-
}
|
|
369
|
+
}
|
|
316
370
|
|
|
317
371
|
/**
|
|
318
372
|
* Update the output format unless options.force is false,
|
|
@@ -323,10 +377,10 @@ const tile = function tile (tile) {
|
|
|
323
377
|
* @param {Boolean} [options.force=true] - force output format, otherwise attempt to use input format
|
|
324
378
|
* @returns {Sharp}
|
|
325
379
|
*/
|
|
326
|
-
|
|
380
|
+
function _updateFormatOut (formatOut, options) {
|
|
327
381
|
this.options.formatOut = (is.object(options) && options.force === false) ? 'input' : formatOut;
|
|
328
382
|
return this;
|
|
329
|
-
}
|
|
383
|
+
}
|
|
330
384
|
|
|
331
385
|
/**
|
|
332
386
|
* Update a Boolean attribute of the this.options Object.
|
|
@@ -335,31 +389,31 @@ const _updateFormatOut = function _updateFormatOut (formatOut, options) {
|
|
|
335
389
|
* @param {Boolean} val
|
|
336
390
|
* @throws {Error} Invalid key
|
|
337
391
|
*/
|
|
338
|
-
|
|
392
|
+
function _setBooleanOption (key, val) {
|
|
339
393
|
if (is.bool(val)) {
|
|
340
394
|
this.options[key] = val;
|
|
341
395
|
} else {
|
|
342
396
|
throw new Error('Invalid ' + key + ' (boolean) ' + val);
|
|
343
397
|
}
|
|
344
|
-
}
|
|
398
|
+
}
|
|
345
399
|
|
|
346
400
|
/**
|
|
347
401
|
* Called by a WriteableStream to notify us it is ready for data.
|
|
348
402
|
* @private
|
|
349
403
|
*/
|
|
350
|
-
|
|
404
|
+
function _read () {
|
|
351
405
|
if (!this.options.streamOut) {
|
|
352
406
|
this.options.streamOut = true;
|
|
353
407
|
this._pipeline();
|
|
354
408
|
}
|
|
355
|
-
}
|
|
409
|
+
}
|
|
356
410
|
|
|
357
411
|
/**
|
|
358
412
|
* Invoke the C++ image processing pipeline
|
|
359
413
|
* Supports callback, stream and promise variants
|
|
360
414
|
* @private
|
|
361
415
|
*/
|
|
362
|
-
|
|
416
|
+
function _pipeline (callback) {
|
|
363
417
|
const that = this;
|
|
364
418
|
if (typeof callback === 'function') {
|
|
365
419
|
// output=file/buffer
|
|
@@ -423,11 +477,15 @@ const _pipeline = function _pipeline (callback) {
|
|
|
423
477
|
return new Promise(function (resolve, reject) {
|
|
424
478
|
that.on('finish', function () {
|
|
425
479
|
that._flattenBufferIn();
|
|
426
|
-
sharp.pipeline(that.options, function (err, data) {
|
|
480
|
+
sharp.pipeline(that.options, function (err, data, info) {
|
|
427
481
|
if (err) {
|
|
428
482
|
reject(err);
|
|
429
483
|
} else {
|
|
430
|
-
|
|
484
|
+
if (that.options.resolveWithObject) {
|
|
485
|
+
resolve({ data: data, info: info });
|
|
486
|
+
} else {
|
|
487
|
+
resolve(data);
|
|
488
|
+
}
|
|
431
489
|
}
|
|
432
490
|
});
|
|
433
491
|
});
|
|
@@ -435,77 +493,21 @@ const _pipeline = function _pipeline (callback) {
|
|
|
435
493
|
} else {
|
|
436
494
|
// output=promise, input=file/buffer
|
|
437
495
|
return new Promise(function (resolve, reject) {
|
|
438
|
-
sharp.pipeline(that.options, function (err, data) {
|
|
496
|
+
sharp.pipeline(that.options, function (err, data, info) {
|
|
439
497
|
if (err) {
|
|
440
498
|
reject(err);
|
|
441
499
|
} else {
|
|
442
|
-
|
|
500
|
+
if (that.options.resolveWithObject) {
|
|
501
|
+
resolve({ data: data, info: info });
|
|
502
|
+
} else {
|
|
503
|
+
resolve(data);
|
|
504
|
+
}
|
|
443
505
|
}
|
|
444
506
|
});
|
|
445
507
|
});
|
|
446
508
|
}
|
|
447
509
|
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Deprecated output options
|
|
451
|
-
/* istanbul ignore next */
|
|
452
|
-
const quality = util.deprecate(function (quality) {
|
|
453
|
-
const formatOut = this.options.formatOut;
|
|
454
|
-
const options = { quality: quality };
|
|
455
|
-
this.jpeg(options).webp(options).tiff(options);
|
|
456
|
-
this.options.formatOut = formatOut;
|
|
457
|
-
return this;
|
|
458
|
-
}, 'quality: use jpeg({ quality: ... }), webp({ quality: ... }) and/or tiff({ quality: ... }) instead');
|
|
459
|
-
/* istanbul ignore next */
|
|
460
|
-
const progressive = util.deprecate(function (progressive) {
|
|
461
|
-
const formatOut = this.options.formatOut;
|
|
462
|
-
const options = { progressive: (progressive !== false) };
|
|
463
|
-
this.jpeg(options).png(options);
|
|
464
|
-
this.options.formatOut = formatOut;
|
|
465
|
-
return this;
|
|
466
|
-
}, 'progressive: use jpeg({ progressive: ... }) and/or png({ progressive: ... }) instead');
|
|
467
|
-
/* istanbul ignore next */
|
|
468
|
-
const compressionLevel = util.deprecate(function (compressionLevel) {
|
|
469
|
-
const formatOut = this.options.formatOut;
|
|
470
|
-
this.png({ compressionLevel: compressionLevel });
|
|
471
|
-
this.options.formatOut = formatOut;
|
|
472
|
-
return this;
|
|
473
|
-
}, 'compressionLevel: use png({ compressionLevel: ... }) instead');
|
|
474
|
-
/* istanbul ignore next */
|
|
475
|
-
const withoutAdaptiveFiltering = util.deprecate(function (withoutAdaptiveFiltering) {
|
|
476
|
-
const formatOut = this.options.formatOut;
|
|
477
|
-
this.png({ adaptiveFiltering: (withoutAdaptiveFiltering === false) });
|
|
478
|
-
this.options.formatOut = formatOut;
|
|
479
|
-
return this;
|
|
480
|
-
}, 'withoutAdaptiveFiltering: use png({ adaptiveFiltering: ... }) instead');
|
|
481
|
-
/* istanbul ignore next */
|
|
482
|
-
const withoutChromaSubsampling = util.deprecate(function (withoutChromaSubsampling) {
|
|
483
|
-
const formatOut = this.options.formatOut;
|
|
484
|
-
this.jpeg({ chromaSubsampling: (withoutChromaSubsampling === false) ? '4:2:0' : '4:4:4' });
|
|
485
|
-
this.options.formatOut = formatOut;
|
|
486
|
-
return this;
|
|
487
|
-
}, 'withoutChromaSubsampling: use jpeg({ chromaSubsampling: "4:4:4" }) instead');
|
|
488
|
-
/* istanbul ignore next */
|
|
489
|
-
const trellisQuantisation = util.deprecate(function (trellisQuantisation) {
|
|
490
|
-
const formatOut = this.options.formatOut;
|
|
491
|
-
this.jpeg({ trellisQuantisation: (trellisQuantisation !== false) });
|
|
492
|
-
this.options.formatOut = formatOut;
|
|
493
|
-
return this;
|
|
494
|
-
}, 'trellisQuantisation: use jpeg({ trellisQuantisation: ... }) instead');
|
|
495
|
-
/* istanbul ignore next */
|
|
496
|
-
const overshootDeringing = util.deprecate(function (overshootDeringing) {
|
|
497
|
-
const formatOut = this.options.formatOut;
|
|
498
|
-
this.jpeg({ overshootDeringing: (overshootDeringing !== false) });
|
|
499
|
-
this.options.formatOut = formatOut;
|
|
500
|
-
return this;
|
|
501
|
-
}, 'overshootDeringing: use jpeg({ overshootDeringing: ... }) instead');
|
|
502
|
-
/* istanbul ignore next */
|
|
503
|
-
const optimiseScans = util.deprecate(function (optimiseScans) {
|
|
504
|
-
const formatOut = this.options.formatOut;
|
|
505
|
-
this.jpeg({ optimiseScans: (optimiseScans !== false) });
|
|
506
|
-
this.options.formatOut = formatOut;
|
|
507
|
-
return this;
|
|
508
|
-
}, 'optimiseScans: use jpeg({ optimiseScans: ... }) instead');
|
|
510
|
+
}
|
|
509
511
|
|
|
510
512
|
/**
|
|
511
513
|
* Decorate the Sharp prototype with output-related functions.
|
|
@@ -532,15 +534,4 @@ module.exports = function (Sharp) {
|
|
|
532
534
|
].forEach(function (f) {
|
|
533
535
|
Sharp.prototype[f.name] = f;
|
|
534
536
|
});
|
|
535
|
-
// Deprecated
|
|
536
|
-
Sharp.prototype.quality = quality;
|
|
537
|
-
Sharp.prototype.progressive = progressive;
|
|
538
|
-
Sharp.prototype.compressionLevel = compressionLevel;
|
|
539
|
-
Sharp.prototype.withoutAdaptiveFiltering = withoutAdaptiveFiltering;
|
|
540
|
-
Sharp.prototype.withoutChromaSubsampling = withoutChromaSubsampling;
|
|
541
|
-
Sharp.prototype.trellisQuantisation = trellisQuantisation;
|
|
542
|
-
Sharp.prototype.trellisQuantization = trellisQuantisation;
|
|
543
|
-
Sharp.prototype.overshootDeringing = overshootDeringing;
|
|
544
|
-
Sharp.prototype.optimiseScans = optimiseScans;
|
|
545
|
-
Sharp.prototype.optimizeScans = optimiseScans;
|
|
546
537
|
};
|
package/lib/resize.js
CHANGED
|
@@ -36,6 +36,7 @@ const strategy = {
|
|
|
36
36
|
* @private
|
|
37
37
|
*/
|
|
38
38
|
const kernel = {
|
|
39
|
+
nearest: 'nearest',
|
|
39
40
|
cubic: 'cubic',
|
|
40
41
|
lanczos2: 'lanczos2',
|
|
41
42
|
lanczos3: 'lanczos3'
|
|
@@ -62,6 +63,7 @@ const interpolator = {
|
|
|
62
63
|
* By default, the resized image is centre cropped to the exact size specified.
|
|
63
64
|
*
|
|
64
65
|
* Possible reduction kernels are:
|
|
66
|
+
* - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
|
|
65
67
|
* - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
|
|
66
68
|
* - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
|
|
67
69
|
* - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
|
|
@@ -89,8 +91,8 @@ const interpolator = {
|
|
|
89
91
|
* // of the image data in inputBuffer
|
|
90
92
|
* });
|
|
91
93
|
*
|
|
92
|
-
* @param {Number} [width] - pixels wide the resultant image should be
|
|
93
|
-
* @param {Number} [height] - pixels high the resultant image should be
|
|
94
|
+
* @param {Number} [width] - pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
|
95
|
+
* @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
|
94
96
|
* @param {Object} [options]
|
|
95
97
|
* @param {String} [options.kernel='lanczos3'] - the kernel to use for image reduction.
|
|
96
98
|
* @param {String} [options.interpolator='bicubic'] - the interpolator to use for image enlargement.
|
|
@@ -99,21 +101,21 @@ const interpolator = {
|
|
|
99
101
|
* @returns {Sharp}
|
|
100
102
|
* @throws {Error} Invalid parameters
|
|
101
103
|
*/
|
|
102
|
-
|
|
104
|
+
function resize (width, height, options) {
|
|
103
105
|
if (is.defined(width)) {
|
|
104
|
-
if (is.integer(width) &&
|
|
106
|
+
if (is.integer(width) && width > 0) {
|
|
105
107
|
this.options.width = width;
|
|
106
108
|
} else {
|
|
107
|
-
throw is.invalidParameterError('width',
|
|
109
|
+
throw is.invalidParameterError('width', 'positive integer', width);
|
|
108
110
|
}
|
|
109
111
|
} else {
|
|
110
112
|
this.options.width = -1;
|
|
111
113
|
}
|
|
112
114
|
if (is.defined(height)) {
|
|
113
|
-
if (is.integer(height) &&
|
|
115
|
+
if (is.integer(height) && height > 0) {
|
|
114
116
|
this.options.height = height;
|
|
115
117
|
} else {
|
|
116
|
-
throw is.invalidParameterError('height',
|
|
118
|
+
throw is.invalidParameterError('height', 'positive integer', height);
|
|
117
119
|
}
|
|
118
120
|
} else {
|
|
119
121
|
this.options.height = -1;
|
|
@@ -142,7 +144,7 @@ const resize = function resize (width, height, options) {
|
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
return this;
|
|
145
|
-
}
|
|
147
|
+
}
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
150
|
* Crop the resized image to the exact size specified, the default behaviour.
|
|
@@ -170,7 +172,7 @@ const resize = function resize (width, height, options) {
|
|
|
170
172
|
* @returns {Sharp}
|
|
171
173
|
* @throws {Error} Invalid parameters
|
|
172
174
|
*/
|
|
173
|
-
|
|
175
|
+
function crop (crop) {
|
|
174
176
|
this.options.canvas = 'crop';
|
|
175
177
|
if (!is.defined(crop)) {
|
|
176
178
|
// Default
|
|
@@ -184,11 +186,14 @@ const crop = function crop (crop) {
|
|
|
184
186
|
} else if (is.integer(crop) && crop >= strategy.entropy) {
|
|
185
187
|
// Strategy
|
|
186
188
|
this.options.crop = crop;
|
|
189
|
+
} else if (is.string(crop) && is.integer(strategy[crop])) {
|
|
190
|
+
// Strategy (string)
|
|
191
|
+
this.options.crop = strategy[crop];
|
|
187
192
|
} else {
|
|
188
193
|
throw is.invalidParameterError('crop', 'valid crop id/name/strategy', crop);
|
|
189
194
|
}
|
|
190
195
|
return this;
|
|
191
|
-
}
|
|
196
|
+
}
|
|
192
197
|
|
|
193
198
|
/**
|
|
194
199
|
* Preserving aspect ratio, resize the image to the maximum `width` or `height` specified
|
|
@@ -213,10 +218,10 @@ const crop = function crop (crop) {
|
|
|
213
218
|
*
|
|
214
219
|
* @returns {Sharp}
|
|
215
220
|
*/
|
|
216
|
-
|
|
221
|
+
function embed () {
|
|
217
222
|
this.options.canvas = 'embed';
|
|
218
223
|
return this;
|
|
219
|
-
}
|
|
224
|
+
}
|
|
220
225
|
|
|
221
226
|
/**
|
|
222
227
|
* Preserving aspect ratio, resize the image to be as large as possible
|
|
@@ -237,10 +242,10 @@ const embed = function embed () {
|
|
|
237
242
|
*
|
|
238
243
|
* @returns {Sharp}
|
|
239
244
|
*/
|
|
240
|
-
|
|
245
|
+
function max () {
|
|
241
246
|
this.options.canvas = 'max';
|
|
242
247
|
return this;
|
|
243
|
-
}
|
|
248
|
+
}
|
|
244
249
|
|
|
245
250
|
/**
|
|
246
251
|
* Preserving aspect ratio, resize the image to be as small as possible
|
|
@@ -250,20 +255,20 @@ const max = function max () {
|
|
|
250
255
|
*
|
|
251
256
|
* @returns {Sharp}
|
|
252
257
|
*/
|
|
253
|
-
|
|
258
|
+
function min () {
|
|
254
259
|
this.options.canvas = 'min';
|
|
255
260
|
return this;
|
|
256
|
-
}
|
|
261
|
+
}
|
|
257
262
|
|
|
258
263
|
/**
|
|
259
264
|
* Ignoring the aspect ratio of the input, stretch the image to
|
|
260
265
|
* the exact `width` and/or `height` provided via `resize`.
|
|
261
266
|
* @returns {Sharp}
|
|
262
267
|
*/
|
|
263
|
-
|
|
268
|
+
function ignoreAspectRatio () {
|
|
264
269
|
this.options.canvas = 'ignore_aspect';
|
|
265
270
|
return this;
|
|
266
|
-
}
|
|
271
|
+
}
|
|
267
272
|
|
|
268
273
|
/**
|
|
269
274
|
* Do not enlarge the output image if the input image width *or* height are already less than the required dimensions.
|
|
@@ -272,10 +277,10 @@ const ignoreAspectRatio = function ignoreAspectRatio () {
|
|
|
272
277
|
* @param {Boolean} [withoutEnlargement=true]
|
|
273
278
|
* @returns {Sharp}
|
|
274
279
|
*/
|
|
275
|
-
|
|
280
|
+
function withoutEnlargement (withoutEnlargement) {
|
|
276
281
|
this.options.withoutEnlargement = is.bool(withoutEnlargement) ? withoutEnlargement : true;
|
|
277
282
|
return this;
|
|
278
|
-
}
|
|
283
|
+
}
|
|
279
284
|
|
|
280
285
|
/**
|
|
281
286
|
* Decorate the Sharp prototype with resize-related functions.
|
package/lib/utility.js
CHANGED
|
@@ -22,7 +22,7 @@ const sharp = require('../build/Release/sharp.node');
|
|
|
22
22
|
* @param {Number} [options.items=100] - is the maximum number of operations to cache
|
|
23
23
|
* @returns {Object}
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
function cache (options) {
|
|
26
26
|
if (is.bool(options)) {
|
|
27
27
|
if (options) {
|
|
28
28
|
// Default cache settings of 50MB, 20 files, 100 items
|
|
@@ -35,7 +35,7 @@ const cache = function cache (options) {
|
|
|
35
35
|
} else {
|
|
36
36
|
return sharp.cache();
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
|
39
39
|
cache(true);
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -57,9 +57,9 @@ cache(true);
|
|
|
57
57
|
* @param {Number} [concurrency]
|
|
58
58
|
* @returns {Number} concurrency
|
|
59
59
|
*/
|
|
60
|
-
|
|
60
|
+
function concurrency (concurrency) {
|
|
61
61
|
return sharp.concurrency(is.integer(concurrency) ? concurrency : null);
|
|
62
|
-
}
|
|
62
|
+
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Provides access to internal task counters.
|
|
@@ -71,9 +71,9 @@ const concurrency = function concurrency (concurrency) {
|
|
|
71
71
|
*
|
|
72
72
|
* @returns {Object}
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
function counters () {
|
|
75
75
|
return sharp.counters();
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Get and set use of SIMD vector unit instructions.
|
|
@@ -95,9 +95,9 @@ const counters = function counters () {
|
|
|
95
95
|
* @param {Boolean} [simd=false]
|
|
96
96
|
* @returns {Boolean}
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
function simd (simd) {
|
|
99
99
|
return sharp.simd(is.bool(simd) ? simd : null);
|
|
100
|
-
}
|
|
100
|
+
}
|
|
101
101
|
simd(false);
|
|
102
102
|
|
|
103
103
|
/**
|