* 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 metad
(fileOut, callback)
| 71 | * @throws {Error} Invalid parameters |
| 72 | */ |
| 73 | function toFile (fileOut, callback) { |
| 74 | let err; |
| 75 | if (!is.string(fileOut)) { |
| 76 | err = new Error('Missing output file path'); |
| 77 | } else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) { |
| 78 | err = new Error('Cannot use same file for input and output'); |
| 79 | } else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.jp2.output.file) { |
| 80 | err = errJp2Save(); |
| 81 | } |
| 82 | if (err) { |
| 83 | if (is.fn(callback)) { |
| 84 | callback(err); |
| 85 | } else { |
| 86 | return Promise.reject(err); |
| 87 | } |
| 88 | } else { |
| 89 | this.options.fileOut = fileOut; |
| 90 | const stack = Error(); |
| 91 | return this._pipeline(callback, stack); |
| 92 | } |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Write output to a Buffer. |
nothing calls this directly
no test coverage detected
searching dependent graphs…