function toFile (fileOut, callback) {
  let err;
  if (!is.string(fileOut)) {
    err = new Error('Missing output file path');
  } else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
    err = new Error('Cannot use same file for input and output');
  }
  if (err) {
    if (is.fn(callback)) {
      callback(err);
    } else {
      return Promise.reject(err);
    }
  } else {
    this.options.fileOut = fileOut;
    return this._pipeline(callback);
  }
  return this;
}
/**
 * Write output image data to a file.
 *
 * If an explicit output format is not selected, it will be inferred from the extension,
 * with JPEG, PNG, WebP, AVIF, TIFF, GIF, DZI, and libvips' V format supported.
 * Note that raw pixel data is only supported for buffer output.
 *
 * By default all metadata will be removed, which includes EXIF-based orientation.
 * See {@link withMetadata} for control over this.
 *
 * The caller is responsible for ensuring directory structures and permissions exist.
 *
 * A `Promise` is returned when `callback` is not provided.
 *
 * @example
 * sharp(input)
 *   .toFile('output.png', (err, info) => { ... });
 *
 * @example
 * sharp(input)
 *   .toFile('output.png')
 *   .then(info => { ... })
 *   .catch(err => { ... });
 *
 * @param {string} fileOut - the path to write the image data to.
 * @param {Function} [callback] - called on completion with two arguments `(err, info)`.
 * `info` contains the output image `format`, `size` (bytes), `width`, `height`,
 * `channels` and `premultiplied` (indicating if premultiplication was used).
 * When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
 * @returns {Promise<Object>} - when no callback is provided
 * @throws {Error} Invalid parameters
 */
Write output image data to a file.
If an explicit output format is not selected, it will be inferred from the extension,
with JPEG, PNG, WebP, AVIF, TIFF, GIF, DZI, and libvips' V format supported.
Note that raw pixel data is only supported for buffer output.

By default all metadata will be removed, which includes EXIF-based orientation.
See  withMetadata for control over this.

The caller is responsible for ensuring directory structures and permissions exist.

A `Promise` is returned when `callback` is not provided.





@param {string} fileOut - the path to write the image data to.
@param {Function} [callback] - called on completion with two arguments `(err, info)`.
Write output image data to a file . If an explicit output format is not selected it will be inferred from the extension with JPEG PNG WebP AVIF TIFF GIF DZI and libvips ' V format supported . Note that raw pixel data is only supported for buffer output . By default all metadata will be removed which includes EXIF - based orientation . See withMetadata for control over this . The caller is responsible for ensuring directory structures and permissions exist . A ` Promise ` is returned when ` callback ` is not provided . @param { string } fileOut - the path to write the image data to . @param { Function } [ callback ] - called on completion with two arguments ` ( err info ) ` .
function toFile (fileOut, callback) {
  let err;
  if (!is.string(fileOut)) {
    err = new Error('Missing output file path');
  } else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
    err = new Error('Cannot use same file for input and output');
  }
  if (err) {
    if (is.fn(callback)) {
      callback(err);
    } else {
      return Promise.reject(err);
    }
  } else {
    this.options.fileOut = fileOut;
    return this._pipeline(callback);
  }
  return this;
}
function toFile ( fileOut , callback ) { let err ; if ( ! is . string ( fileOut ) ) { err = new Error ( 'Missing output file path' ) ; } else if ( is . string ( this . options . input . file ) && path . resolve ( this . options . input . file ) === path . resolve ( fileOut ) ) { err = new Error ( 'Cannot use same file for input and output' ) ; } if ( err ) { if ( is . fn ( callback ) ) { callback ( err ) ; } else { return Promise . reject ( err ) ; } } else { this . options . fileOut = fileOut ; return this . _pipeline ( callback ) ; } return this ; }
Write output image data to a file.
Write output image data to a file .