Skip to content

Commit 7a1a1cf

Browse files
committed
Docs: add/correct some operation examples
1 parent ea599ad commit 7a1a1cf

2 files changed

Lines changed: 121 additions & 26 deletions

File tree

docs/api-operation.md

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
5353

5454
* `flip` **[Boolean][6]** (optional, default `true`)
5555

56+
### Examples
57+
58+
```javascript
59+
const output = await sharp(input).flip().toBuffer();
60+
```
61+
5662
Returns **Sharp**
5763

5864
## flop
@@ -64,6 +70,12 @@ The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
6470

6571
* `flop` **[Boolean][6]** (optional, default `true`)
6672

73+
### Examples
74+
75+
```javascript
76+
const output = await sharp(input).flop().toBuffer();
77+
```
78+
6779
Returns **Sharp**
6880

6981
## affine
@@ -178,7 +190,15 @@ When used without parameters the default window is 3x3.
178190

179191
* `size` **[number][1]** square mask size: size x size (optional, default `3`)
180192

181-
<!---->
193+
### Examples
194+
195+
```javascript
196+
const output = await sharp(input).median().toBuffer();
197+
```
198+
199+
```javascript
200+
const output = await sharp(input).median(5).toBuffer();
201+
```
182202

183203
* Throws **[Error][5]** Invalid parameters
184204

@@ -277,6 +297,12 @@ Enhance output image contrast by stretching its luminance to cover the full dyna
277297

278298
* `normalise` **[Boolean][6]** (optional, default `true`)
279299

300+
### Examples
301+
302+
```javascript
303+
const output = await sharp(input).normalise().toBuffer();
304+
```
305+
280306
Returns **Sharp**
281307

282308
## normalize
@@ -287,6 +313,12 @@ Alternative spelling of normalise.
287313

288314
* `normalize` **[Boolean][6]** (optional, default `true`)
289315

316+
### Examples
317+
318+
```javascript
319+
const output = await sharp(input).normalize().toBuffer();
320+
```
321+
290322
Returns **Sharp**
291323

292324
## clahe
@@ -306,7 +338,16 @@ This will, in general, enhance the clarity of the image by bringing out darker d
306338
cumulative histogram. A value of 0 disables contrast limiting. Valid values
307339
are integers in the range 0-100 (inclusive) (optional, default `3`)
308340

309-
<!---->
341+
### Examples
342+
343+
```javascript
344+
const output = await sharp(input)
345+
.clahe({
346+
width: 3,
347+
height: 3,
348+
})
349+
.toBuffer();
350+
```
310351

311352
* Throws **[Error][5]** Invalid parameters
312353

@@ -458,28 +499,41 @@ brightness is multiplicative whereas lightness is additive.
458499
### Examples
459500

460501
```javascript
461-
sharp(input)
502+
// increase brightness by a factor of 2
503+
const output = await sharp(input)
462504
.modulate({
463-
brightness: 2 // increase brightness by a factor of 2
464-
});
505+
brightness: 2
506+
})
507+
.toBuffer();
508+
```
465509

466-
sharp(input)
510+
```javascript
511+
// hue-rotate by 180 degrees
512+
const output = await sharp(input)
467513
.modulate({
468-
hue: 180 // hue-rotate by 180 degrees
469-
});
514+
hue: 180
515+
})
516+
.toBuffer();
517+
```
470518

471-
sharp(input)
519+
```javascript
520+
// increase lightness by +50
521+
const output = await sharp(input)
472522
.modulate({
473-
lightness: 50 // increase lightness by +50
474-
});
523+
lightness: 50
524+
})
525+
.toBuffer();
526+
```
475527

528+
```javascript
476529
// decreate brightness and saturation while also hue-rotating by 90 degrees
477-
sharp(input)
530+
const output = await sharp(input)
478531
.modulate({
479532
brightness: 0.5,
480533
saturation: 0.5,
481-
hue: 90
482-
});
534+
hue: 90,
535+
})
536+
.toBuffer();
483537
```
484538

485539
Returns **Sharp**

lib/operation.js

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ function rotate (angle, options) {
6363
/**
6464
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
6565
* The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
66+
*
67+
* @example
68+
* const output = await sharp(input).flip().toBuffer();
69+
*
6670
* @param {Boolean} [flip=true]
6771
* @returns {Sharp}
6872
*/
@@ -74,6 +78,10 @@ function flip (flip) {
7478
/**
7579
* Flop the image about the horizontal X axis. This always occurs after rotation, if any.
7680
* The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
81+
*
82+
* @example
83+
* const output = await sharp(input).flop().toBuffer();
84+
*
7785
* @param {Boolean} [flop=true]
7886
* @returns {Sharp}
7987
*/
@@ -291,6 +299,13 @@ function sharpen (options) {
291299
/**
292300
* Apply median filter.
293301
* When used without parameters the default window is 3x3.
302+
*
303+
* @example
304+
* const output = await sharp(input).median().toBuffer();
305+
*
306+
* @example
307+
* const output = await sharp(input).median(5).toBuffer();
308+
*
294309
* @param {number} [size=3] square mask size: size x size
295310
* @returns {Sharp}
296311
* @throws {Error} Invalid parameters
@@ -421,6 +436,10 @@ function negate (options) {
421436

422437
/**
423438
* Enhance output image contrast by stretching its luminance to cover the full dynamic range.
439+
*
440+
* @example
441+
* const output = await sharp(input).normalise().toBuffer();
442+
*
424443
* @param {Boolean} [normalise=true]
425444
* @returns {Sharp}
426445
*/
@@ -431,6 +450,10 @@ function normalise (normalise) {
431450

432451
/**
433452
* Alternative spelling of normalise.
453+
*
454+
* @example
455+
* const output = await sharp(input).normalize().toBuffer();
456+
*
434457
* @param {Boolean} [normalize=true]
435458
* @returns {Sharp}
436459
*/
@@ -446,6 +469,14 @@ function normalize (normalize) {
446469
*
447470
* @since 0.28.3
448471
*
472+
* @example
473+
* const output = await sharp(input)
474+
* .clahe({
475+
* width: 3,
476+
* height: 3,
477+
* })
478+
* .toBuffer();
479+
*
449480
* @param {Object} options
450481
* @param {number} options.width - integer width of the region in pixels.
451482
* @param {number} options.height - integer height of the region in pixels.
@@ -655,28 +686,38 @@ function recomb (inputMatrix) {
655686
* @since 0.22.1
656687
*
657688
* @example
658-
* sharp(input)
689+
* // increase brightness by a factor of 2
690+
* const output = await sharp(input)
659691
* .modulate({
660-
* brightness: 2 // increase brightness by a factor of 2
661-
* });
692+
* brightness: 2
693+
* })
694+
* .toBuffer();
662695
*
663-
* sharp(input)
696+
* @example
697+
* // hue-rotate by 180 degrees
698+
* const output = await sharp(input)
664699
* .modulate({
665-
* hue: 180 // hue-rotate by 180 degrees
666-
* });
700+
* hue: 180
701+
* })
702+
* .toBuffer();
667703
*
668-
* sharp(input)
704+
* @example
705+
* // increase lightness by +50
706+
* const output = await sharp(input)
669707
* .modulate({
670-
* lightness: 50 // increase lightness by +50
671-
* });
708+
* lightness: 50
709+
* })
710+
* .toBuffer();
672711
*
712+
* @example
673713
* // decreate brightness and saturation while also hue-rotating by 90 degrees
674-
* sharp(input)
714+
* const output = await sharp(input)
675715
* .modulate({
676716
* brightness: 0.5,
677717
* saturation: 0.5,
678-
* hue: 90
679-
* });
718+
* hue: 90,
719+
* })
720+
* .toBuffer();
680721
*
681722
* @param {Object} [options]
682723
* @param {number} [options.brightness] Brightness multiplier

0 commit comments

Comments
 (0)