Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-contain/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 to the given width and height keeping the aspect ratio. Some parts of the image may be letter boxed.
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
contain: function contain(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
} // permit any sort of optional parameters combination
25
26
27
if (typeof alignBits === 'string') {
28
if (typeof mode === 'function' && typeof cb === 'undefined') cb = mode;
29
mode = alignBits;
30
alignBits = null;
31
}
32
33
if (typeof alignBits === 'function') {
34
if (typeof cb === 'undefined') cb = alignBits;
35
mode = null;
36
alignBits = null;
37
}
38
39
if (typeof mode === 'function' && typeof cb === 'undefined') {
40
cb = mode;
41
mode = null;
42
}
43
44
alignBits = alignBits || this.constructor.HORIZONTAL_ALIGN_CENTER | this.constructor.VERTICAL_ALIGN_MIDDLE;
45
var hbits = alignBits & (1 << 3) - 1;
46
var vbits = alignBits >> 3; // check if more flags than one is in the bit sets
47
48
if (!(hbits !== 0 && !(hbits & hbits - 1) || vbits !== 0 && !(vbits & vbits - 1))) {
49
return _utils.throwError.call(this, 'only use one flag per alignment direction', cb);
50
}
51
52
var alignH = hbits >> 1; // 0, 1, 2
53
54
var alignV = vbits >> 1; // 0, 1, 2
55
56
var f = w / h > this.bitmap.width / this.bitmap.height ? h / this.bitmap.height : w / this.bitmap.width;
57
var c = this.cloneQuiet().scale(f, mode);
58
this.resize(w, h, mode);
59
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
60
this.bitmap.data.writeUInt32BE(this._background, idx);
61
});
62
this.blit(c, (this.bitmap.width - c.bitmap.width) / 2 * alignH, (this.bitmap.height - c.bitmap.height) / 2 * alignV);
63
64
if ((0, _utils.isNodePattern)(cb)) {
65
cb.call(this, null, this);
66
}
67
68
return this;
69
}
70
};
71
};
72
73
exports["default"] = _default;
74
module.exports = exports.default;
75
//# sourceMappingURL=index.js.map
76