Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-cover/dist/index.js
1129 views
1
"use strict";
2
3
Object.defineProperty(exports, "__esModule", {
4
value: true
5
});
6
exports["default"] = void 0;
7
8
var _utils = require("@jimp/utils");
9
10
/**
11
* Scale the image so the given width and height keeping the aspect ratio. Some parts of the image may be clipped.
12
* @param {number} w the width to resize the image to
13
* @param {number} h the height to resize the image to
14
* @param {number} alignBits (optional) A bitmask for horizontal and vertical alignment
15
* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
16
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
17
* @returns {Jimp} this for chaining of methods
18
*/
19
var _default = function _default() {
20
return {
21
cover: function cover(w, h, alignBits, mode, cb) {
22
if (typeof w !== 'number' || typeof h !== 'number') {
23
return _utils.throwError.call(this, 'w and h must be numbers', cb);
24
}
25
26
if (alignBits && typeof alignBits === 'function' && typeof cb === 'undefined') {
27
cb = alignBits;
28
alignBits = null;
29
mode = null;
30
} else if (typeof mode === 'function' && typeof cb === 'undefined') {
31
cb = mode;
32
mode = null;
33
}
34
35
alignBits = alignBits || this.constructor.HORIZONTAL_ALIGN_CENTER | this.constructor.VERTICAL_ALIGN_MIDDLE;
36
var hbits = alignBits & (1 << 3) - 1;
37
var vbits = alignBits >> 3; // check if more flags than one is in the bit sets
38
39
if (!(hbits !== 0 && !(hbits & hbits - 1) || vbits !== 0 && !(vbits & vbits - 1))) return _utils.throwError.call(this, 'only use one flag per alignment direction', cb);
40
var alignH = hbits >> 1; // 0, 1, 2
41
42
var alignV = vbits >> 1; // 0, 1, 2
43
44
var f = w / h > this.bitmap.width / this.bitmap.height ? w / this.bitmap.width : h / this.bitmap.height;
45
this.scale(f, mode);
46
this.crop((this.bitmap.width - w) / 2 * alignH, (this.bitmap.height - h) / 2 * alignV, w, h);
47
48
if ((0, _utils.isNodePattern)(cb)) {
49
cb.call(this, null, this);
50
}
51
52
return this;
53
}
54
};
55
};
56
57
exports["default"] = _default;
58
module.exports = exports.default;
59
//# sourceMappingURL=index.js.map
60