Skip to content

Colour manipulation

tint

tint(tint) ⇒ Sharp

Tint the image using the provided colour. An alpha channel may be present and will be unchanged by the operation.

Throws:

  • Error Invalid parameter
ParamTypeDescription
tintstring | ObjectParsed by the color module.

Example

const output = await sharp(input)
.tint({ r: 255, g: 240, b: 16 })
.toBuffer();

greyscale

greyscale([greyscale]) ⇒ Sharp

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) colour channels. This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel. An alpha channel may be present, and will be unchanged by the operation.

ParamTypeDefault
[greyscale]Booleantrue

Example

const output = await sharp(input).greyscale().toBuffer();

grayscale

grayscale([grayscale]) ⇒ Sharp

Alternative spelling of greyscale.

ParamTypeDefault
[grayscale]Booleantrue

pipelineColourspace

pipelineColourspace([colourspace]) ⇒ Sharp

Set the pipeline colourspace.

The input image will be converted to the provided colourspace at the start of the pipeline. All operations will use this colourspace before converting to the output colourspace, as defined by toColourspace.

Throws:

  • Error Invalid parameters

Since: 0.29.0

ParamTypeDescription
[colourspace]stringpipeline colourspace e.g. rgb16, scrgb, lab, grey16

Example

// Run pipeline in 16 bits per channel RGB while converting final result to 8 bits per channel sRGB.
await sharp(input)
.pipelineColourspace('rgb16')
.toColourspace('srgb')
.toFile('16bpc-pipeline-to-8bpc-output.png')

pipelineColorspace

pipelineColorspace([colorspace]) ⇒ Sharp

Alternative spelling of pipelineColourspace.

Throws:

  • Error Invalid parameters
ParamTypeDescription
[colorspace]stringpipeline colorspace.

toColourspace

toColourspace([colourspace]) ⇒ Sharp

Set the output colourspace. By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.

Throws:

  • Error Invalid parameters
ParamTypeDescription
[colourspace]stringoutput colourspace e.g. srgb, rgb, cmyk, lab, b-w

Example

// Output 16 bits per pixel RGB
await sharp(input)
.toColourspace('rgb16')
.toFile('16-bpp.png')

toColorspace

toColorspace([colorspace]) ⇒ Sharp

Alternative spelling of toColourspace.

Throws:

  • Error Invalid parameters
ParamTypeDescription
[colorspace]stringoutput colorspace.