Skip to content

Commit

Permalink
Docs: improve colour vs color consistency
Browse files Browse the repository at this point in the history
API supports both, docs prefer colour
  • Loading branch information
lovell committed Sep 6, 2024
1 parent 807d924 commit b249357
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/api-colour.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const output = await sharp(input)
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.
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 color channel.
which will produce an output image containing one colour channel.
An alpha channel may be present, and will be unchanged by the operation.


Expand Down
2 changes: 1 addition & 1 deletion docs/api-constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages`
| [options.page] | <code>number</code> | <code>0</code> | Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based. |
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
| [options.pdfBackground] | <code>string</code> \| <code>Object</code> | | Background color to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, poppler-glib, ImageMagick, or GraphicsMagick. |
| [options.pdfBackground] | <code>string</code> \| <code>Object</code> | | Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. |
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`. |
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
Expand Down
2 changes: 1 addition & 1 deletion docs/api-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const output = await sharp(input).flop().toBuffer();
Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.

You must provide an array of length 4 or a 2x2 affine transformation matrix.
By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.

In the case of a 2x2 matrix, the transform is:
Expand Down
4 changes: 2 additions & 2 deletions lib/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function tint (tint) {
/**
* 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.
* 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 color channel.
* which will produce an output image containing one colour channel.
* An alpha channel may be present, and will be unchanged by the operation.
*
* @example
Expand Down
2 changes: 1 addition & 1 deletion lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const debuglog = util.debuglog('sharp');
* @param {number} [options.page=0] - Page number to start extracting from for multi-page input (GIF, WebP, TIFF), zero based.
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
* @param {string|Object} [options.pdfBackground] - Background color to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, poppler-glib, ImageMagick, or GraphicsMagick.
* @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
* @param {number} [options.raw.width] - integral number of pixels wide.
Expand Down
27 changes: 14 additions & 13 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ declare namespace sharp {
* @param tint Parsed by the color module.
* @returns A sharp instance that can be used to chain operations
*/
tint(tint: Color): Sharp;
tint(tint: Colour | Color): 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) 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.
* 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.
* @param greyscale true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
Expand Down Expand Up @@ -401,7 +401,7 @@ declare namespace sharp {
/**
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
*
* In the case of a 2x2 matrix, the transform is:
Expand Down Expand Up @@ -935,8 +935,8 @@ declare namespace sharp {
subifd?: number | undefined;
/** Level to extract from a multi-level input (OpenSlide), zero based. (optional, default 0) */
level?: number | undefined;
/** Background color to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, poppler-glib, ImageMagick, or GraphicsMagick. */
pdfBackground?: Color | undefined;
/** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
pdfBackground?: Colour | Color | undefined;
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
animated?: boolean | undefined;
/** Describes raw pixel input image data. See raw() for pixel ordering. */
Expand Down Expand Up @@ -987,7 +987,7 @@ declare namespace sharp {
/** Number of bands e.g. 3 for RGB, 4 for RGBA */
channels: Channels;
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
background: Color;
background: Colour | Color;
/** Describes a noise to be created. */
noise?: Noise | undefined;
}
Expand Down Expand Up @@ -1341,7 +1341,7 @@ declare namespace sharp {

interface RotateOptions {
/** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
background?: Color | undefined;
background?: Colour | Color | undefined;
}

type Precision = 'integer' | 'float' | 'approximate';
Expand All @@ -1357,7 +1357,7 @@ declare namespace sharp {

interface FlattenOptions {
/** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
background?: Color | undefined;
background?: Colour | Color | undefined;
}

interface NegateOptions {
Expand All @@ -1382,7 +1382,7 @@ declare namespace sharp {
/** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
position?: number | string | undefined;
/** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
background?: Color | undefined;
background?: Colour | Color | undefined;
/** The kernel to use for image reduction. (optional, default 'lanczos3') */
kernel?: keyof KernelEnum | undefined;
/** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
Expand Down Expand Up @@ -1425,14 +1425,14 @@ declare namespace sharp {
/** single pixel count to right edge (optional, default 0) */
right?: number | undefined;
/** background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
background?: Color | undefined;
background?: Colour | Color | undefined;
/** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
extendWith?: ExtendWith | undefined;
}

interface TrimOptions {
/** Background colour, parsed by the color module, defaults to that of the top-left pixel. (optional) */
background?: Color | undefined;
background?: Colour | Color | undefined;
/** Allowed difference from the above colour, a positive number. (optional, default 10) */
threshold?: number | undefined;
/** Does the input more closely resemble line art (e.g. vector) rather than being photographic? (optional, default false) */
Expand All @@ -1453,7 +1453,8 @@ declare namespace sharp {
alpha?: number | undefined;
}

type Color = string | RGBA;
type Colour = string | RGBA;
type Color = Colour;

interface Kernel {
/** width of the kernel in pixels. */
Expand Down
6 changes: 3 additions & 3 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const is = require('./is');
const sharp = require('./sharp');

/**
* Justication alignment
* Justification alignment
* @member
* @private
*/
Expand All @@ -26,7 +26,7 @@ const align = {
function _inputOptionsFromObject (obj) {
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground } = obj;
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground].some(is.defined)
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd }
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground }
: undefined;
}

Expand Down Expand Up @@ -222,7 +222,7 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
}
}
// PDF background color
// PDF background colour
if (is.defined(inputOptions.pdfBackground)) {
this._setBackgroundColourOption('pdfBackground', inputOptions.pdfBackground);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function flop (flop) {
* Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.
*
* You must provide an array of length 4 or a 2x2 affine transformation matrix.
* By default, new pixels are filled with a black background. You can provide a background color with the `background` option.
* By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.
* A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.
*
* In the case of a 2x2 matrix, the transform is:
Expand Down
7 changes: 6 additions & 1 deletion test/types/sharp.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,9 @@ sharp(input).composite([
density: 72,
failOn: "truncated"
}
])
])

const colour: sharp.Colour = '#fff';
const color: sharp.Color = '#fff';
sharp({ pdfBackground: colour });
sharp({ pdfBackground: color });

0 comments on commit b249357

Please sign in to comment.