Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-scale/dist/index.js
1126 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
var _default = function _default() {
11
return {
12
/**
13
* Uniformly scales the image by a factor.
14
* @param {number} f the factor to scale the image by
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
scale: function scale(f, mode, cb) {
20
if (typeof f !== 'number') {
21
return _utils.throwError.call(this, 'f must be a number', cb);
22
}
23
24
if (f < 0) {
25
return _utils.throwError.call(this, 'f must be a positive number', cb);
26
}
27
28
if (typeof mode === 'function' && typeof cb === 'undefined') {
29
cb = mode;
30
mode = null;
31
}
32
33
var w = this.bitmap.width * f;
34
var h = this.bitmap.height * f;
35
this.resize(w, h, mode);
36
37
if ((0, _utils.isNodePattern)(cb)) {
38
cb.call(this, null, this);
39
}
40
41
return this;
42
},
43
44
/**
45
* Scale the image to the largest size that fits inside the rectangle that has the given width and height.
46
* @param {number} w the width to resize the image to
47
* @param {number} h the height to resize the image to
48
* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
49
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
50
* @returns {Jimp} this for chaining of methods
51
*/
52
scaleToFit: function scaleToFit(w, h, mode, cb) {
53
if (typeof w !== 'number' || typeof h !== 'number') {
54
return _utils.throwError.call(this, 'w and h must be numbers', cb);
55
}
56
57
if (typeof mode === 'function' && typeof cb === 'undefined') {
58
cb = mode;
59
mode = null;
60
}
61
62
var f = w / h > this.bitmap.width / this.bitmap.height ? h / this.bitmap.height : w / this.bitmap.width;
63
this.scale(f, mode);
64
65
if ((0, _utils.isNodePattern)(cb)) {
66
cb.call(this, null, this);
67
}
68
69
return this;
70
}
71
};
72
};
73
74
exports["default"] = _default;
75
module.exports = exports.default;
76
//# sourceMappingURL=index.js.map
77