Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-circle/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
/**
11
* Creates a circle out of an image.
12
* @param {function(Error, Jimp)} options (optional) radius, x, y
13
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
14
* @returns {Jimp} this for chaining of methods
15
*/
16
var _default = function _default() {
17
return {
18
circle: function circle() {
19
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
var cb = arguments.length > 1 ? arguments[1] : undefined;
21
22
if (typeof options === 'function') {
23
cb = options;
24
options = {};
25
}
26
27
var radius = options.radius || (this.bitmap.width > this.bitmap.height ? this.bitmap.height : this.bitmap.width) / 2;
28
var center = {
29
x: typeof options.x === 'number' ? options.x : this.bitmap.width / 2,
30
y: typeof options.y === 'number' ? options.y : this.bitmap.height / 2
31
};
32
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
33
var curR = Math.sqrt(Math.pow(x - center.x, 2) + Math.pow(y - center.y, 2));
34
35
if (radius - curR <= 0.0) {
36
this.bitmap.data[idx + 3] = 0;
37
} else if (radius - curR < 1.0) {
38
this.bitmap.data[idx + 3] = 255 * (radius - curR);
39
}
40
});
41
42
if ((0, _utils.isNodePattern)(cb)) {
43
cb.call(this, null, this);
44
}
45
46
return this;
47
}
48
};
49
};
50
51
exports["default"] = _default;
52
module.exports = exports.default;
53
//# sourceMappingURL=index.js.map
54