sharp/docs/api-colour.md
2018-06-20 08:14:03 +01:00

137 lines
3.3 KiB
Markdown

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [background][1]
- [Parameters][2]
- [tint][3]
- [Parameters][4]
- [greyscale][5]
- [Parameters][6]
- [grayscale][7]
- [Parameters][8]
- [toColourspace][9]
- [Parameters][10]
- [toColorspace][11]
- [Parameters][12]
## background
Set the background for the `embed`, `flatten` and `extend` operations.
The default background is `{r: 0, g: 0, b: 0, alpha: 1}`, black without transparency.
Delegates to the _color_ module, which can throw an Error
but is liberal in what it accepts, clipping values to sensible min/max.
The alpha value is a float between `0` (transparent) and `1` (opaque).
### Parameters
- `rgba` **([String][13] \| [Object][14])** parsed by the [color][15] module to extract values for red, green, blue and alpha.
- Throws **[Error][16]** Invalid parameter
Returns **Sharp**
## tint
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.
### Parameters
- `rgb` **([String][13] \| [Object][14])** parsed by the [color][15] module to extract chroma values.
- Throws **[Error][16]** Invalid parameter
Returns **Sharp**
## greyscale
Convert to 8-bit greyscale; 256 shades of grey.
This is a linear operation. If the input image is in a non-linear colour space such as sRGB, use `gamma()` with `greyscale()` for the best results.
By default the output image will be web-friendly sRGB and contain three (identical) color channels.
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.
### Parameters
- `greyscale` **[Boolean][17]** (optional, default `true`)
Returns **Sharp**
## grayscale
Alternative spelling of `greyscale`.
### Parameters
- `grayscale` **[Boolean][17]** (optional, default `true`)
Returns **Sharp**
## toColourspace
Set the output colourspace.
By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
### Parameters
- `colourspace` **[String][13]?** output colourspace e.g. `srgb`, `rgb`, `cmyk`, `lab`, `b-w` [...][18]
- Throws **[Error][16]** Invalid parameters
Returns **Sharp**
## toColorspace
Alternative spelling of `toColourspace`.
### Parameters
- `colorspace` **[String][13]?** output colorspace.
- Throws **[Error][16]** Invalid parameters
Returns **Sharp**
[1]: #background
[2]: #parameters
[3]: #tint
[4]: #parameters-1
[5]: #greyscale
[6]: #parameters-2
[7]: #grayscale
[8]: #parameters-3
[9]: #tocolourspace
[10]: #parameters-4
[11]: #tocolorspace
[12]: #parameters-5
[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[15]: https://www.npmjs.org/package/color
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[18]: https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/enumtypes.c#L568