Path: blob/master/node_modules/@jimp/plugin-scale/es/index.js
1126 views
"use strict";12Object.defineProperty(exports, "__esModule", {3value: true4});5exports["default"] = void 0;67var _utils = require("@jimp/utils");89var _default = function _default() {10return {11/**12* Uniformly scales the image by a factor.13* @param {number} f the factor to scale the image by14* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)15* @param {function(Error, Jimp)} cb (optional) a callback for when complete16* @returns {Jimp} this for chaining of methods17*/18scale: function scale(f, mode, cb) {19if (typeof f !== 'number') {20return _utils.throwError.call(this, 'f must be a number', cb);21}2223if (f < 0) {24return _utils.throwError.call(this, 'f must be a positive number', cb);25}2627if (typeof mode === 'function' && typeof cb === 'undefined') {28cb = mode;29mode = null;30}3132var w = this.bitmap.width * f;33var h = this.bitmap.height * f;34this.resize(w, h, mode);3536if ((0, _utils.isNodePattern)(cb)) {37cb.call(this, null, this);38}3940return this;41},4243/**44* Scale the image to the largest size that fits inside the rectangle that has the given width and height.45* @param {number} w the width to resize the image to46* @param {number} h the height to resize the image to47* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)48* @param {function(Error, Jimp)} cb (optional) a callback for when complete49* @returns {Jimp} this for chaining of methods50*/51scaleToFit: function scaleToFit(w, h, mode, cb) {52if (typeof w !== 'number' || typeof h !== 'number') {53return _utils.throwError.call(this, 'w and h must be numbers', cb);54}5556if (typeof mode === 'function' && typeof cb === 'undefined') {57cb = mode;58mode = null;59}6061var f = w / h > this.bitmap.width / this.bitmap.height ? h / this.bitmap.height : w / this.bitmap.width;62this.scale(f, mode);6364if ((0, _utils.isNodePattern)(cb)) {65cb.call(this, null, this);66}6768return this;69}70};71};7273exports["default"] = _default;74//# sourceMappingURL=index.js.map7576