* Resize image to `width`, `height` or `width x height`. * * When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are: * - `cover`: (default) Preserving aspect ratio, attempt to ensure the image covers both provided dimensions by cropping/cli
(widthOrOptions, height, options)
| 256 | * @throws {Error} Invalid parameters |
| 257 | */ |
| 258 | function resize (widthOrOptions, height, options) { |
| 259 | if (isResizeExpected(this.options)) { |
| 260 | this.options.debuglog('ignoring previous resize options'); |
| 261 | } |
| 262 | if (this.options.widthPost !== -1) { |
| 263 | this.options.debuglog('operation order will be: extract, resize, extract'); |
| 264 | } |
| 265 | if (is.defined(widthOrOptions)) { |
| 266 | if (is.object(widthOrOptions) && !is.defined(options)) { |
| 267 | options = widthOrOptions; |
| 268 | } else if (is.integer(widthOrOptions) && widthOrOptions > 0) { |
| 269 | this.options.width = widthOrOptions; |
| 270 | } else { |
| 271 | throw is.invalidParameterError('width', 'positive integer', widthOrOptions); |
| 272 | } |
| 273 | } else { |
| 274 | this.options.width = -1; |
| 275 | } |
| 276 | if (is.defined(height)) { |
| 277 | if (is.integer(height) && height > 0) { |
| 278 | this.options.height = height; |
| 279 | } else { |
| 280 | throw is.invalidParameterError('height', 'positive integer', height); |
| 281 | } |
| 282 | } else { |
| 283 | this.options.height = -1; |
| 284 | } |
| 285 | if (is.object(options)) { |
| 286 | // Width |
| 287 | if (is.defined(options.width)) { |
| 288 | if (is.integer(options.width) && options.width > 0) { |
| 289 | this.options.width = options.width; |
| 290 | } else { |
| 291 | throw is.invalidParameterError('width', 'positive integer', options.width); |
| 292 | } |
| 293 | } |
| 294 | // Height |
| 295 | if (is.defined(options.height)) { |
| 296 | if (is.integer(options.height) && options.height > 0) { |
| 297 | this.options.height = options.height; |
| 298 | } else { |
| 299 | throw is.invalidParameterError('height', 'positive integer', options.height); |
| 300 | } |
| 301 | } |
| 302 | // Fit |
| 303 | if (is.defined(options.fit)) { |
| 304 | const canvas = mapFitToCanvas[options.fit]; |
| 305 | if (is.string(canvas)) { |
| 306 | this.options.canvas = canvas; |
| 307 | } else { |
| 308 | throw is.invalidParameterError('fit', 'valid fit', options.fit); |
| 309 | } |
| 310 | } |
| 311 | // Position |
| 312 | if (is.defined(options.position)) { |
| 313 | const pos = is.integer(options.position) |
| 314 | ? options.position |
| 315 | : strategy[options.position] || position[options.position] || gravity[options.position]; |
no test coverage detected
searching dependent graphs…