Path: blob/master/node_modules/@jimp/plugin-resize/es/index.js
1126 views
"use strict";12var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");34Object.defineProperty(exports, "__esModule", {5value: true6});7exports["default"] = void 0;89var _utils = require("@jimp/utils");1011var _resize = _interopRequireDefault(require("./modules/resize"));1213var _resize2 = _interopRequireDefault(require("./modules/resize2"));1415var _default = function _default() {16return {17constants: {18RESIZE_NEAREST_NEIGHBOR: 'nearestNeighbor',19RESIZE_BILINEAR: 'bilinearInterpolation',20RESIZE_BICUBIC: 'bicubicInterpolation',21RESIZE_HERMITE: 'hermiteInterpolation',22RESIZE_BEZIER: 'bezierInterpolation'23},24"class": {25/**26* Resizes the image to a set width and height using a 2-pass bilinear algorithm27* @param {number} w the width to resize the image to (or Jimp.AUTO)28* @param {number} h the height to resize the image to (or Jimp.AUTO)29* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)30* @param {function(Error, Jimp)} cb (optional) a callback for when complete31* @returns {Jimp} this for chaining of methods32*/33resize: function resize(w, h, mode, cb) {34if (typeof w !== 'number' || typeof h !== 'number') {35return _utils.throwError.call(this, 'w and h must be numbers', cb);36}3738if (typeof mode === 'function' && typeof cb === 'undefined') {39cb = mode;40mode = null;41}4243if (w === this.constructor.AUTO && h === this.constructor.AUTO) {44return _utils.throwError.call(this, 'w and h cannot both be set to auto', cb);45}4647if (w === this.constructor.AUTO) {48w = this.bitmap.width * (h / this.bitmap.height);49}5051if (h === this.constructor.AUTO) {52h = this.bitmap.height * (w / this.bitmap.width);53}5455if (w < 0 || h < 0) {56return _utils.throwError.call(this, 'w and h must be positive numbers', cb);57} // round inputs585960w = Math.round(w);61h = Math.round(h);6263if (typeof _resize2["default"][mode] === 'function') {64var dst = {65data: Buffer.alloc(w * h * 4),66width: w,67height: h68};6970_resize2["default"][mode](this.bitmap, dst);7172this.bitmap = dst;73} else {74var image = this;75var resize = new _resize["default"](this.bitmap.width, this.bitmap.height, w, h, true, true, function (buffer) {76image.bitmap.data = Buffer.from(buffer);77image.bitmap.width = w;78image.bitmap.height = h;79});80resize.resize(this.bitmap.data);81}8283if ((0, _utils.isNodePattern)(cb)) {84cb.call(this, null, this);85}8687return this;88}89}90};91};9293exports["default"] = _default;94//# sourceMappingURL=index.js.map9596