Path: blob/master/node_modules/@jimp/plugin-fisheye/es/index.js
1129 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 {object} options (optional) r: radius of effect12* @param {function(Error, Jimp)} cb (optional) a callback for when complete13* @returns {Jimp} this for chaining of methods14*/15var _default = function _default() {16return {17fisheye: function fisheye() {18var _this = this;1920var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {21r: 2.522};23var cb = arguments.length > 1 ? arguments[1] : undefined;2425if (typeof options === 'function') {26cb = options;27options = {28r: 2.529};30}3132var source = this.cloneQuiet();33var _source$bitmap = source.bitmap,34width = _source$bitmap.width,35height = _source$bitmap.height;36source.scanQuiet(0, 0, width, height, function (x, y) {37var hx = x / width;38var hy = y / height;39var r = Math.sqrt(Math.pow(hx - 0.5, 2) + Math.pow(hy - 0.5, 2));40var rn = 2 * Math.pow(r, options.r);41var cosA = (hx - 0.5) / r;42var sinA = (hy - 0.5) / r;43var newX = Math.round((rn * cosA + 0.5) * width);44var newY = Math.round((rn * sinA + 0.5) * height);45var color = source.getPixelColor(newX, newY);4647_this.setPixelColor(color, x, y);48});49/* Set center pixel color, otherwise it will be transparent */5051this.setPixelColor(source.getPixelColor(width / 2, height / 2), width / 2, height / 2);5253if ((0, _utils.isNodePattern)(cb)) {54cb.call(this, null, this);55}5657return this;58}59};60};6162exports["default"] = _default;63//# sourceMappingURL=index.js.map6465