Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-fisheye/es/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
* Creates a circle out of an image.
12
* @param {object} options (optional) r: radius of effect
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
fisheye: function fisheye() {
19
var _this = this;
20
21
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
22
r: 2.5
23
};
24
var cb = arguments.length > 1 ? arguments[1] : undefined;
25
26
if (typeof options === 'function') {
27
cb = options;
28
options = {
29
r: 2.5
30
};
31
}
32
33
var source = this.cloneQuiet();
34
var _source$bitmap = source.bitmap,
35
width = _source$bitmap.width,
36
height = _source$bitmap.height;
37
source.scanQuiet(0, 0, width, height, function (x, y) {
38
var hx = x / width;
39
var hy = y / height;
40
var r = Math.sqrt(Math.pow(hx - 0.5, 2) + Math.pow(hy - 0.5, 2));
41
var rn = 2 * Math.pow(r, options.r);
42
var cosA = (hx - 0.5) / r;
43
var sinA = (hy - 0.5) / r;
44
var newX = Math.round((rn * cosA + 0.5) * width);
45
var newY = Math.round((rn * sinA + 0.5) * height);
46
var color = source.getPixelColor(newX, newY);
47
48
_this.setPixelColor(color, x, y);
49
});
50
/* Set center pixel color, otherwise it will be transparent */
51
52
this.setPixelColor(source.getPixelColor(width / 2, height / 2), width / 2, height / 2);
53
54
if ((0, _utils.isNodePattern)(cb)) {
55
cb.call(this, null, this);
56
}
57
58
return this;
59
}
60
};
61
};
62
63
exports["default"] = _default;
64
//# sourceMappingURL=index.js.map
65