mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Add support to extend for extendWith, allows copy/mirror/repeat (#3556)
This commit is contained in:
@@ -197,6 +197,7 @@ const Sharp = function (input, options) {
|
||||
extendLeft: 0,
|
||||
extendRight: 0,
|
||||
extendBackground: [0, 0, 0, 255],
|
||||
extendWith: 'background',
|
||||
withoutEnlargement: false,
|
||||
withoutReduction: false,
|
||||
affineMatrix: [],
|
||||
|
||||
6
lib/index.d.ts
vendored
6
lib/index.d.ts
vendored
@@ -755,7 +755,7 @@ declare namespace sharp {
|
||||
resize(options: ResizeOptions): Sharp;
|
||||
|
||||
/**
|
||||
* Extends/pads the edges of the image with the provided background colour.
|
||||
* Extends/pads the edges of the image with either the provided background colour or pixels derived from the image.
|
||||
* This operation will always occur after resizing and extraction, if any.
|
||||
* @param extend single pixel count to add to all edges or an Object with per-edge counts
|
||||
* @throws {Error} Invalid parameters
|
||||
@@ -1245,6 +1245,8 @@ declare namespace sharp {
|
||||
sigma?: number | undefined;
|
||||
}
|
||||
|
||||
type ExtendWith = 'background' | 'copy' | 'repeat' | 'mirror';
|
||||
|
||||
interface ExtendOptions {
|
||||
/** single pixel count to top edge (optional, default 0) */
|
||||
top?: number | undefined;
|
||||
@@ -1256,6 +1258,8 @@ declare namespace sharp {
|
||||
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;
|
||||
/** how the extension is done, one of: "background", "copy", "repeat", "mirror" (optional, default `'background'`) */
|
||||
extendWith?: ExtendWith | undefined;
|
||||
}
|
||||
|
||||
interface TrimOptions {
|
||||
|
||||
@@ -36,6 +36,18 @@ const position = {
|
||||
'left top': 8
|
||||
};
|
||||
|
||||
/**
|
||||
* How to extend the image.
|
||||
* @member
|
||||
* @private
|
||||
*/
|
||||
const extendWith = {
|
||||
background: 'background',
|
||||
copy: 'copy',
|
||||
repeat: 'repeat',
|
||||
mirror: 'mirror'
|
||||
};
|
||||
|
||||
/**
|
||||
* Strategies for automagic cover behaviour.
|
||||
* @member
|
||||
@@ -393,6 +405,13 @@ function extend (extend) {
|
||||
}
|
||||
}
|
||||
this._setBackgroundColourOption('extendBackground', extend.background);
|
||||
if (is.defined(extend.extendWith)) {
|
||||
if (is.string(extendWith[extend.extendWith])) {
|
||||
this.options.extendWith = extendWith[extend.extendWith];
|
||||
} else {
|
||||
throw is.invalidParameterError('extendWith', 'valid value', extend.extendWith);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw is.invalidParameterError('extend', 'integer or object', extend);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user