function trim (options) {
  this.options.trimThreshold = 10;
  if (is.defined(options)) {
    if (is.object(options)) {
      if (is.defined(options.background)) {
        this._setBackgroundColourOption('trimBackground', options.background);
      }
      if (is.defined(options.threshold)) {
        if (is.number(options.threshold) && options.threshold >= 0) {
          this.options.trimThreshold = options.threshold;
        } else {
          throw is.invalidParameterError('threshold', 'positive number', options.threshold);
        }
      }
      if (is.defined(options.lineArt)) {
        this._setBooleanOption('trimLineArt', options.lineArt);
      }
    } else {
      throw is.invalidParameterError('trim', 'object', options);
    }
  }
  if (isRotationExpected(this.options)) {
    this.options.rotateBeforePreExtract = true;
  }
  return this;
}
Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.

Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.

If the result of this operation would trim an image to nothing then no change is made.

The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.

@example
// Trim pixels with a colour similar to that of the top-left pixel.
await sharp(input)
  .trim()
  .toFile(output);

@example
// Trim pixels with the exact same colour as that of the top-left pixel.
await sharp(input)
  .trim({
    threshold: 0
  })
  .toFile(output);

@example
// Assume input is line art and trim only pixels with a similar colour to red.
const output = await sharp(input)
  .trim({
    background: "#FF0000",
    lineArt: true
  })
  .toBuffer();

@example
// Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
const output = await sharp(input)
  .trim({
    background: "yellow",
    threshold: 42,
  })
  .toBuffer();

@param {Object} [options]
@param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
@param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
@param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
@returns {Sharp}
@throws {Error} Invalid parameters