diff --git a/docs/api-colour.md b/docs/api-colour.md index ed34cf77..75f4c09e 100644 --- a/docs/api-colour.md +++ b/docs/api-colour.md @@ -9,7 +9,13 @@ An alpha channel may be present and will be unchanged by the operation. * `rgb` **([string][1] | [Object][2])** parsed by the [color][3] module to extract chroma values. - +### Examples + +```javascript +const output = await sharp(input) + .tint({ r: 255, g: 240, b: 16 }) + .toBuffer(); +``` * Throws **[Error][4]** Invalid parameter @@ -28,6 +34,12 @@ An alpha channel may be present, and will be unchanged by the operation. * `greyscale` **[Boolean][5]** (optional, default `true`) +### Examples + +```javascript +const output = await sharp(input).greyscale().toBuffer(); +``` + Returns **Sharp** ## grayscale diff --git a/docs/api-composite.md b/docs/api-composite.md index 3030a53a..1f0d5df3 100644 --- a/docs/api-composite.md +++ b/docs/api-composite.md @@ -46,6 +46,23 @@ and [https://www.cairographics.org/operators/][2] ### Examples +```javascript +await sharp(background) + .composite([ + { input: layer1, gravity: 'northwest' }, + { input: layer2, gravity: 'southeast' }, + ]) + .toFile('combined.png'); +``` + +```javascript +const output = await sharp('input.gif', { animated: true }) + .composite([ + { input: 'overlay.png', tile: true, blend: 'saturate' } + ]) + .toBuffer(); +``` + ```javascript sharp('input.png') .rotate(180) diff --git a/lib/colour.js b/lib/colour.js index 16937dfc..88a908bd 100644 --- a/lib/colour.js +++ b/lib/colour.js @@ -19,6 +19,11 @@ const colourspace = { * Tint the image using the provided chroma while preserving the image luminance. * An alpha channel may be present and will be unchanged by the operation. * + * @example + * const output = await sharp(input) + * .tint({ r: 255, g: 240, b: 16 }) + * .toBuffer(); + * * @param {string|Object} rgb - parsed by the [color](https://www.npmjs.org/package/color) module to extract chroma values. * @returns {Sharp} * @throws {Error} Invalid parameter @@ -37,6 +42,10 @@ function tint (rgb) { * This may be overridden by other sharp operations such as `toColourspace('b-w')`, * which will produce an output image containing one color channel. * An alpha channel may be present, and will be unchanged by the operation. + * + * @example + * const output = await sharp(input).greyscale().toBuffer(); + * * @param {Boolean} [greyscale=true] * @returns {Sharp} */ diff --git a/lib/composite.js b/lib/composite.js index 38d17793..d42e4ec9 100644 --- a/lib/composite.js +++ b/lib/composite.js @@ -56,6 +56,21 @@ const blend = { * @since 0.22.0 * * @example + * await sharp(background) + * .composite([ + * { input: layer1, gravity: 'northwest' }, + * { input: layer2, gravity: 'southeast' }, + * ]) + * .toFile('combined.png'); + * + * @example + * const output = await sharp('input.gif', { animated: true }) + * .composite([ + * { input: 'overlay.png', tile: true, blend: 'saturate' } + * ]) + * .toBuffer(); + * + * @example * sharp('input.png') * .rotate(180) * .resize(300)