Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-resize/dist/index.js
1126 views
1
"use strict";
2
3
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5
Object.defineProperty(exports, "__esModule", {
6
value: true
7
});
8
exports["default"] = void 0;
9
10
var _utils = require("@jimp/utils");
11
12
var _resize = _interopRequireDefault(require("./modules/resize"));
13
14
var _resize2 = _interopRequireDefault(require("./modules/resize2"));
15
16
var _default = function _default() {
17
return {
18
constants: {
19
RESIZE_NEAREST_NEIGHBOR: 'nearestNeighbor',
20
RESIZE_BILINEAR: 'bilinearInterpolation',
21
RESIZE_BICUBIC: 'bicubicInterpolation',
22
RESIZE_HERMITE: 'hermiteInterpolation',
23
RESIZE_BEZIER: 'bezierInterpolation'
24
},
25
"class": {
26
/**
27
* Resizes the image to a set width and height using a 2-pass bilinear algorithm
28
* @param {number} w the width to resize the image to (or Jimp.AUTO)
29
* @param {number} h the height to resize the image to (or Jimp.AUTO)
30
* @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
31
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
32
* @returns {Jimp} this for chaining of methods
33
*/
34
resize: function resize(w, h, mode, cb) {
35
if (typeof w !== 'number' || typeof h !== 'number') {
36
return _utils.throwError.call(this, 'w and h must be numbers', cb);
37
}
38
39
if (typeof mode === 'function' && typeof cb === 'undefined') {
40
cb = mode;
41
mode = null;
42
}
43
44
if (w === this.constructor.AUTO && h === this.constructor.AUTO) {
45
return _utils.throwError.call(this, 'w and h cannot both be set to auto', cb);
46
}
47
48
if (w === this.constructor.AUTO) {
49
w = this.bitmap.width * (h / this.bitmap.height);
50
}
51
52
if (h === this.constructor.AUTO) {
53
h = this.bitmap.height * (w / this.bitmap.width);
54
}
55
56
if (w < 0 || h < 0) {
57
return _utils.throwError.call(this, 'w and h must be positive numbers', cb);
58
} // round inputs
59
60
61
w = Math.round(w);
62
h = Math.round(h);
63
64
if (typeof _resize2["default"][mode] === 'function') {
65
var dst = {
66
data: Buffer.alloc(w * h * 4),
67
width: w,
68
height: h
69
};
70
71
_resize2["default"][mode](this.bitmap, dst);
72
73
this.bitmap = dst;
74
} else {
75
var image = this;
76
var resize = new _resize["default"](this.bitmap.width, this.bitmap.height, w, h, true, true, function (buffer) {
77
image.bitmap.data = Buffer.from(buffer);
78
image.bitmap.width = w;
79
image.bitmap.height = h;
80
});
81
resize.resize(this.bitmap.data);
82
}
83
84
if ((0, _utils.isNodePattern)(cb)) {
85
cb.call(this, null, this);
86
}
87
88
return this;
89
}
90
}
91
};
92
};
93
94
exports["default"] = _default;
95
module.exports = exports.default;
96
//# sourceMappingURL=index.js.map
97