Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-shadow/es/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)
13
* opacity - opacity of the shadow between 0 and 1
14
* size,- of the shadow
15
* blur - how blurry the shadow is
16
* x- x position of shadow
17
* y - y position of shadow
18
* @param {function(Error, Jimp)} cb (optional) a callback for when complete
19
* @returns {Jimp} this for chaining of methods
20
*/
21
var _default = function _default() {
22
return {
23
shadow: function shadow() {
24
var _this = this;
25
26
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
var cb = arguments.length > 1 ? arguments[1] : undefined;
28
29
if (typeof options === 'function') {
30
cb = options;
31
options = {};
32
}
33
34
var _options = options,
35
_options$opacity = _options.opacity,
36
opacity = _options$opacity === void 0 ? 0.7 : _options$opacity,
37
_options$size = _options.size,
38
size = _options$size === void 0 ? 1.1 : _options$size,
39
_options$x = _options.x,
40
x = _options$x === void 0 ? -25 : _options$x,
41
_options$y = _options.y,
42
y = _options$y === void 0 ? 25 : _options$y,
43
_options$blur = _options.blur,
44
blur = _options$blur === void 0 ? 5 : _options$blur; // clone the image
45
46
var orig = this.clone();
47
var shadow = this.clone(); // turn all it's pixels black
48
49
shadow.scan(0, 0, shadow.bitmap.width, shadow.bitmap.height, function (x, y, idx) {
50
shadow.bitmap.data[idx] = 0x00;
51
shadow.bitmap.data[idx + 1] = 0x00;
52
shadow.bitmap.data[idx + 2] = 0x00; // up the opacity a little,
53
54
shadow.bitmap.data[idx + 3] = shadow.constructor.limit255(shadow.bitmap.data[idx + 3] * opacity);
55
_this.bitmap.data[idx] = 0x00;
56
_this.bitmap.data[idx + 1] = 0x00;
57
_this.bitmap.data[idx + 2] = 0x00;
58
_this.bitmap.data[idx + 3] = 0x00;
59
}); // enlarge it. This creates a "shadow".
60
61
shadow.resize(shadow.bitmap.width * size, shadow.bitmap.height * size).blur(blur); // Then blit the "shadow" onto the background and the image on top of that.
62
63
this.composite(shadow, x, y);
64
this.composite(orig, 0, 0);
65
66
if ((0, _utils.isNodePattern)(cb)) {
67
cb.call(this, null, this);
68
}
69
70
return this;
71
}
72
};
73
};
74
75
exports["default"] = _default;
76
//# sourceMappingURL=index.js.map
77