Switch from custom trim op to vips_find_trim #914

This commit is contained in:
Lovell Fuller
2018-10-02 11:24:32 +01:00
parent 11900945eb
commit 21fbe546b8
8 changed files with 34 additions and 65 deletions

View File

@@ -134,7 +134,7 @@ const Sharp = function (input, options) {
sharpenJagged: 2,
threshold: 0,
thresholdGrayscale: true,
trimTolerance: 0,
trimThreshold: 0,
gamma: 0,
greyscale: false,
normalise: 0,

View File

@@ -359,18 +359,18 @@ function extract (options) {
}
/**
* Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel.
* @param {Number} [tolerance=10] value between 1 and 99 representing the percentage similarity.
* Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
* @param {Number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
function trim (tolerance) {
if (!is.defined(tolerance)) {
this.options.trimTolerance = 10;
} else if (is.integer(tolerance) && is.inRange(tolerance, 1, 99)) {
this.options.trimTolerance = tolerance;
function trim (threshold) {
if (!is.defined(threshold)) {
this.options.trimThreshold = 10;
} else if (is.number(threshold) && threshold > 0) {
this.options.trimThreshold = threshold;
} else {
throw new Error('Invalid trim tolerance (1 to 99) ' + tolerance);
throw is.invalidParameterError('threshold', 'number greater than zero', threshold);
}
return this;
}