Path: blob/master/node_modules/@jimp/plugin-cover/dist/index.js
1129 views
"use strict";12Object.defineProperty(exports, "__esModule", {3value: true4});5exports["default"] = void 0;67var _utils = require("@jimp/utils");89/**10* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.11* @param {number} w the width to resize the image to12* @param {number} h the height to resize the image to13* @param {number} alignBits (optional) A bitmask for horizontal and vertical alignment14* @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*/18var _default = function _default() {19return {20cover: function cover(w, h, alignBits, mode, cb) {21if (typeof w !== 'number' || typeof h !== 'number') {22return _utils.throwError.call(this, 'w and h must be numbers', cb);23}2425if (alignBits && typeof alignBits === 'function' && typeof cb === 'undefined') {26cb = alignBits;27alignBits = null;28mode = null;29} else if (typeof mode === 'function' && typeof cb === 'undefined') {30cb = mode;31mode = null;32}3334alignBits = alignBits || this.constructor.HORIZONTAL_ALIGN_CENTER | this.constructor.VERTICAL_ALIGN_MIDDLE;35var hbits = alignBits & (1 << 3) - 1;36var vbits = alignBits >> 3; // check if more flags than one is in the bit sets3738if (!(hbits !== 0 && !(hbits & hbits - 1) || vbits !== 0 && !(vbits & vbits - 1))) return _utils.throwError.call(this, 'only use one flag per alignment direction', cb);39var alignH = hbits >> 1; // 0, 1, 24041var alignV = vbits >> 1; // 0, 1, 24243var f = w / h > this.bitmap.width / this.bitmap.height ? w / this.bitmap.width : h / this.bitmap.height;44this.scale(f, mode);45this.crop((this.bitmap.width - w) / 2 * alignH, (this.bitmap.height - h) / 2 * alignV, w, h);4647if ((0, _utils.isNodePattern)(cb)) {48cb.call(this, null, this);49}5051return this;52}53};54};5556exports["default"] = _default;57module.exports = exports.default;58//# sourceMappingURL=index.js.map5960