Path: blob/master/node_modules/@jimp/plugin-circle/es/index.js
1126 views
"use strict";12Object.defineProperty(exports, "__esModule", {3value: true4});5exports["default"] = void 0;67var _utils = require("@jimp/utils");89/**10* Creates a circle out of an image.11* @param {function(Error, Jimp)} options (optional) radius, x, y12* @param {function(Error, Jimp)} cb (optional) a callback for when complete13* @returns {Jimp} this for chaining of methods14*/15var _default = function _default() {16return {17circle: function circle() {18var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};19var cb = arguments.length > 1 ? arguments[1] : undefined;2021if (typeof options === 'function') {22cb = options;23options = {};24}2526var radius = options.radius || (this.bitmap.width > this.bitmap.height ? this.bitmap.height : this.bitmap.width) / 2;27var center = {28x: typeof options.x === 'number' ? options.x : this.bitmap.width / 2,29y: typeof options.y === 'number' ? options.y : this.bitmap.height / 230};31this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {32var curR = Math.sqrt(Math.pow(x - center.x, 2) + Math.pow(y - center.y, 2));3334if (radius - curR <= 0.0) {35this.bitmap.data[idx + 3] = 0;36} else if (radius - curR < 1.0) {37this.bitmap.data[idx + 3] = 255 * (radius - curR);38}39});4041if ((0, _utils.isNodePattern)(cb)) {42cb.call(this, null, this);43}4445return this;46}47};48};4950exports["default"] = _default;51//# sourceMappingURL=index.js.map5253