{"version":3,"file":"index.js","names":["isNodePattern","throwError","scale","f","mode","cb","call","w","bitmap","width","h","height","resize","scaleToFit"],"sources":["../src/index.js"],"sourcesContent":["import { isNodePattern, throwError } from \"@jimp/utils\";\n\nexport default () => ({\n /**\n * Uniformly scales the image by a factor.\n * @param {number} f the factor to scale the image by\n * @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n scale(f, mode, cb) {\n if (typeof f !== \"number\") {\n return throwError.call(this, \"f must be a number\", cb);\n }\n\n if (f < 0) {\n return throwError.call(this, \"f must be a positive number\", cb);\n }\n\n if (typeof mode === \"function\" && typeof cb === \"undefined\") {\n cb = mode;\n mode = null;\n }\n\n const w = this.bitmap.width * f;\n const h = this.bitmap.height * f;\n this.resize(w, h, mode);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n\n /**\n * Scale the image to the largest size that fits inside the rectangle that has the given width and height.\n * @param {number} w the width to resize the image to\n * @param {number} h the height to resize the image to\n * @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)\n * @param {function(Error, Jimp)} cb (optional) a callback for when complete\n * @returns {Jimp} this for chaining of methods\n */\n scaleToFit(w, h, mode, cb) {\n if (typeof w !== \"number\" || typeof h !== \"number\") {\n return throwError.call(this, \"w and h must be numbers\", cb);\n }\n\n if (typeof mode === \"function\" && typeof cb === \"undefined\") {\n cb = mode;\n mode = null;\n }\n\n const f =\n w / h > this.bitmap.width / this.bitmap.height\n ? h / this.bitmap.height\n : w / this.bitmap.width;\n this.scale(f, mode);\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this);\n }\n\n return this;\n },\n});\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,aAAa;AAEvD,gBAAe,OAAO;EACpB;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,KAAK,CAACC,CAAC,EAAEC,IA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