mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose erode and dilate operations #4243
This commit is contained in:
committed by
Lovell Fuller
parent
03e1b19764
commit
031c808aa5
@@ -443,6 +443,52 @@ function blur (options) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand foreground objects using the dilate morphological operator.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .dilate()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Number} [width=1] dilation width in pixels.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function dilate (width) {
|
||||
if (!is.defined(width)) {
|
||||
this.options.dilateWidth = 1;
|
||||
} else if (is.integer(width) && width > 0) {
|
||||
this.options.dilateWidth = width;
|
||||
} else {
|
||||
throw is.invalidParameterError('dilate', 'positive integer', dilate);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shrink foreground objects using the erode morphological operator.
|
||||
*
|
||||
* @example
|
||||
* const output = await sharp(input)
|
||||
* .erode()
|
||||
* .toBuffer();
|
||||
*
|
||||
* @param {Number} [width=1] erosion width in pixels.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function erode (width) {
|
||||
if (!is.defined(width)) {
|
||||
this.options.erodeWidth = 1;
|
||||
} else if (is.integer(width) && width > 0) {
|
||||
this.options.erodeWidth = width;
|
||||
} else {
|
||||
throw is.invalidParameterError('erode', 'positive integer', erode);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge alpha transparency channel, if any, with a background, then remove the alpha channel.
|
||||
*
|
||||
@@ -958,6 +1004,8 @@ module.exports = function (Sharp) {
|
||||
flop,
|
||||
affine,
|
||||
sharpen,
|
||||
erode,
|
||||
dilate,
|
||||
median,
|
||||
blur,
|
||||
flatten,
|
||||
|
||||
Reference in New Issue
Block a user