mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Docs: add/correct some operation examples
This commit is contained in:
parent
ea599ade10
commit
7a1a1cf9e8
@ -53,6 +53,12 @@ The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
|
|
||||||
* `flip` **[Boolean][6]** (optional, default `true`)
|
* `flip` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input).flip().toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## flop
|
## flop
|
||||||
@ -64,6 +70,12 @@ The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
|||||||
|
|
||||||
* `flop` **[Boolean][6]** (optional, default `true`)
|
* `flop` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input).flop().toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## affine
|
## affine
|
||||||
@ -178,7 +190,15 @@ When used without parameters the default window is 3x3.
|
|||||||
|
|
||||||
* `size` **[number][1]** square mask size: size x size (optional, default `3`)
|
* `size` **[number][1]** square mask size: size x size (optional, default `3`)
|
||||||
|
|
||||||
<!---->
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input).median().toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input).median(5).toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
@ -277,6 +297,12 @@ Enhance output image contrast by stretching its luminance to cover the full dyna
|
|||||||
|
|
||||||
* `normalise` **[Boolean][6]** (optional, default `true`)
|
* `normalise` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input).normalise().toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## normalize
|
## normalize
|
||||||
@ -287,6 +313,12 @@ Alternative spelling of normalise.
|
|||||||
|
|
||||||
* `normalize` **[Boolean][6]** (optional, default `true`)
|
* `normalize` **[Boolean][6]** (optional, default `true`)
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input).normalize().toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## clahe
|
## clahe
|
||||||
@ -306,7 +338,16 @@ This will, in general, enhance the clarity of the image by bringing out darker d
|
|||||||
cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
cumulative histogram. A value of 0 disables contrast limiting. Valid values
|
||||||
are integers in the range 0-100 (inclusive) (optional, default `3`)
|
are integers in the range 0-100 (inclusive) (optional, default `3`)
|
||||||
|
|
||||||
<!---->
|
### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const output = await sharp(input)
|
||||||
|
.clahe({
|
||||||
|
width: 3,
|
||||||
|
height: 3,
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
* Throws **[Error][5]** Invalid parameters
|
* Throws **[Error][5]** Invalid parameters
|
||||||
|
|
||||||
@ -458,28 +499,41 @@ brightness is multiplicative whereas lightness is additive.
|
|||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
sharp(input)
|
// increase brightness by a factor of 2
|
||||||
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
brightness: 2 // increase brightness by a factor of 2
|
brightness: 2
|
||||||
});
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
sharp(input)
|
```javascript
|
||||||
|
// hue-rotate by 180 degrees
|
||||||
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
hue: 180 // hue-rotate by 180 degrees
|
hue: 180
|
||||||
});
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
sharp(input)
|
```javascript
|
||||||
|
// increase lightness by +50
|
||||||
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
lightness: 50 // increase lightness by +50
|
lightness: 50
|
||||||
});
|
})
|
||||||
|
.toBuffer();
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
// decreate brightness and saturation while also hue-rotating by 90 degrees
|
// decreate brightness and saturation while also hue-rotating by 90 degrees
|
||||||
sharp(input)
|
const output = await sharp(input)
|
||||||
.modulate({
|
.modulate({
|
||||||
brightness: 0.5,
|
brightness: 0.5,
|
||||||
saturation: 0.5,
|
saturation: 0.5,
|
||||||
hue: 90
|
hue: 90,
|
||||||
});
|
})
|
||||||
|
.toBuffer();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
@ -63,6 +63,10 @@ function rotate (angle, options) {
|
|||||||
/**
|
/**
|
||||||
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
|
||||||
* The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
* The use of `flip` implies the removal of the EXIF `Orientation` tag, if any.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).flip().toBuffer();
|
||||||
|
*
|
||||||
* @param {Boolean} [flip=true]
|
* @param {Boolean} [flip=true]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
@ -74,6 +78,10 @@ function flip (flip) {
|
|||||||
/**
|
/**
|
||||||
* Flop the image about the horizontal X axis. This always occurs after rotation, if any.
|
* Flop the image about the horizontal X axis. This always occurs after rotation, if any.
|
||||||
* The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
* The use of `flop` implies the removal of the EXIF `Orientation` tag, if any.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).flop().toBuffer();
|
||||||
|
*
|
||||||
* @param {Boolean} [flop=true]
|
* @param {Boolean} [flop=true]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
@ -291,6 +299,13 @@ function sharpen (options) {
|
|||||||
/**
|
/**
|
||||||
* Apply median filter.
|
* Apply median filter.
|
||||||
* When used without parameters the default window is 3x3.
|
* When used without parameters the default window is 3x3.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).median().toBuffer();
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).median(5).toBuffer();
|
||||||
|
*
|
||||||
* @param {number} [size=3] square mask size: size x size
|
* @param {number} [size=3] square mask size: size x size
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
@ -421,6 +436,10 @@ function negate (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Enhance output image contrast by stretching its luminance to cover the full dynamic range.
|
* Enhance output image contrast by stretching its luminance to cover the full dynamic range.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).normalise().toBuffer();
|
||||||
|
*
|
||||||
* @param {Boolean} [normalise=true]
|
* @param {Boolean} [normalise=true]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
@ -431,6 +450,10 @@ function normalise (normalise) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Alternative spelling of normalise.
|
* Alternative spelling of normalise.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input).normalize().toBuffer();
|
||||||
|
*
|
||||||
* @param {Boolean} [normalize=true]
|
* @param {Boolean} [normalize=true]
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
*/
|
*/
|
||||||
@ -446,6 +469,14 @@ function normalize (normalize) {
|
|||||||
*
|
*
|
||||||
* @since 0.28.3
|
* @since 0.28.3
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
|
* const output = await sharp(input)
|
||||||
|
* .clahe({
|
||||||
|
* width: 3,
|
||||||
|
* height: 3,
|
||||||
|
* })
|
||||||
|
* .toBuffer();
|
||||||
|
*
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @param {number} options.width - integer width of the region in pixels.
|
* @param {number} options.width - integer width of the region in pixels.
|
||||||
* @param {number} options.height - integer height of the region in pixels.
|
* @param {number} options.height - integer height of the region in pixels.
|
||||||
@ -655,28 +686,38 @@ function recomb (inputMatrix) {
|
|||||||
* @since 0.22.1
|
* @since 0.22.1
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp(input)
|
* // increase brightness by a factor of 2
|
||||||
|
* const output = await sharp(input)
|
||||||
* .modulate({
|
* .modulate({
|
||||||
* brightness: 2 // increase brightness by a factor of 2
|
* brightness: 2
|
||||||
* });
|
* })
|
||||||
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* sharp(input)
|
* @example
|
||||||
|
* // hue-rotate by 180 degrees
|
||||||
|
* const output = await sharp(input)
|
||||||
* .modulate({
|
* .modulate({
|
||||||
* hue: 180 // hue-rotate by 180 degrees
|
* hue: 180
|
||||||
* });
|
* })
|
||||||
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* sharp(input)
|
* @example
|
||||||
|
* // increase lightness by +50
|
||||||
|
* const output = await sharp(input)
|
||||||
* .modulate({
|
* .modulate({
|
||||||
* lightness: 50 // increase lightness by +50
|
* lightness: 50
|
||||||
* });
|
* })
|
||||||
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
* // decreate brightness and saturation while also hue-rotating by 90 degrees
|
* // decreate brightness and saturation while also hue-rotating by 90 degrees
|
||||||
* sharp(input)
|
* const output = await sharp(input)
|
||||||
* .modulate({
|
* .modulate({
|
||||||
* brightness: 0.5,
|
* brightness: 0.5,
|
||||||
* saturation: 0.5,
|
* saturation: 0.5,
|
||||||
* hue: 90
|
* hue: 90,
|
||||||
* });
|
* })
|
||||||
|
* .toBuffer();
|
||||||
*
|
*
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
* @param {number} [options.brightness] Brightness multiplier
|
* @param {number} [options.brightness] Brightness multiplier
|
||||||
|
Loading…
x
Reference in New Issue
Block a user