index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _utils = require("@jimp/utils");
  7. /**
  8. * Creates a circle out of an image.
  9. * @param {function(Error, Jimp)} options (optional)
  10. * opacity - opacity of the shadow between 0 and 1
  11. * size,- of the shadow
  12. * blur - how blurry the shadow is
  13. * x- x position of shadow
  14. * y - y position of shadow
  15. * @param {function(Error, Jimp)} cb (optional) a callback for when complete
  16. * @returns {Jimp} this for chaining of methods
  17. */
  18. var _default = function _default() {
  19. return {
  20. shadow: function shadow() {
  21. var _this = this;
  22. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  23. var cb = arguments.length > 1 ? arguments[1] : undefined;
  24. if (typeof options === 'function') {
  25. cb = options;
  26. options = {};
  27. }
  28. var _options = options,
  29. _options$opacity = _options.opacity,
  30. opacity = _options$opacity === void 0 ? 0.7 : _options$opacity,
  31. _options$size = _options.size,
  32. size = _options$size === void 0 ? 1.1 : _options$size,
  33. _options$x = _options.x,
  34. x = _options$x === void 0 ? -25 : _options$x,
  35. _options$y = _options.y,
  36. y = _options$y === void 0 ? 25 : _options$y,
  37. _options$blur = _options.blur,
  38. blur = _options$blur === void 0 ? 5 : _options$blur; // clone the image
  39. var orig = this.clone();
  40. var shadow = this.clone(); // turn all it's pixels black
  41. shadow.scan(0, 0, shadow.bitmap.width, shadow.bitmap.height, function (x, y, idx) {
  42. shadow.bitmap.data[idx] = 0x00;
  43. shadow.bitmap.data[idx + 1] = 0x00;
  44. shadow.bitmap.data[idx + 2] = 0x00; // up the opacity a little,
  45. shadow.bitmap.data[idx + 3] = shadow.constructor.limit255(shadow.bitmap.data[idx + 3] * opacity);
  46. _this.bitmap.data[idx] = 0x00;
  47. _this.bitmap.data[idx + 1] = 0x00;
  48. _this.bitmap.data[idx + 2] = 0x00;
  49. _this.bitmap.data[idx + 3] = 0x00;
  50. }); // enlarge it. This creates a "shadow".
  51. 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.
  52. this.composite(shadow, x, y);
  53. this.composite(orig, 0, 0);
  54. if ((0, _utils.isNodePattern)(cb)) {
  55. cb.call(this, null, this);
  56. }
  57. return this;
  58. }
  59. };
  60. };
  61. exports["default"] = _default;
  62. //# sourceMappingURL=index.js.map