How to use the @jimp/utils.isNodePattern function in @jimp/utils

To help you get started, we’ve selected a few @jimp/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oliver-moran / jimp / packages / core / src / index.js View on Github external
yi = y % this.bitmap.height;
      }
    }

    let i = (this.bitmap.width * yi + xi) << 2;

    // if out of bounds index is -1
    if (xi < 0 || xi >= this.bitmap.width) {
      i = -1;
    }

    if (yi < 0 || yi >= this.bitmap.height) {
      i = -1;
    }

    if (isNodePattern(cb)) {
      cb.call(this, null, i);
    }

    return i;
  }
github oliver-moran / jimp / packages / plugin-cover / src / index.js View on Github external
const alignH = hbits >> 1; // 0, 1, 2
    const alignV = vbits >> 1; // 0, 1, 2

    const f =
      w / h > this.bitmap.width / this.bitmap.height
        ? w / this.bitmap.width
        : h / this.bitmap.height;
    this.scale(f, mode);
    this.crop(
      ((this.bitmap.width - w) / 2) * alignH,
      ((this.bitmap.height - h) / 2) * alignV,
      w,
      h
    );

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
});
github NiGhTTraX / mugshot / packages / mugshot / src / vendor / jimp-crop.ts View on Github external
const bitmap = Buffer.allocUnsafe(w * h * 4);
      let offset = 0;

      this.scanQuiet(x, y, w, h, function(x, y, idx) {
        const data = this.bitmap.data.readUInt32BE(idx, true);
        bitmap.writeUInt32BE(data, offset, true);
        offset += 4;
      });

      this.bitmap.data = bitmap;
    }

    this.bitmap.width = w;
    this.bitmap.height = h;

    if (isNodePattern(cb)) {
      // @ts-ignore because cb can be undefined and isNodePattern doesn't narrow
      cb.call(this, null, this);
    }

    return this;
  });
}
github oliver-moran / jimp / packages / plugin-color / src / index.js View on Github external
if (gSum > 255) {
        gSum = 255;
      }

      if (bSum > 255) {
        bSum = 255;
      }

      newData[idx + 0] = rSum;
      newData[idx + 1] = gSum;
      newData[idx + 2] = bSum;
    });

    this.bitmap.data = newData;

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  },
github oliver-moran / jimp / packages / plugin-blur / src / index.js View on Github external
}

          p1 = x + vmin[y];
          p2 = x + vmax[y];

          rsum += red[p1] - red[p2];
          gsum += green[p1] - green[p2];
          bsum += blue[p1] - blue[p2];
          asum += alpha[p1] - alpha[p2];

          yi += this.bitmap.width << 2;
        }
      }
    }

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
});
github oliver-moran / jimp / packages / plugin-invert / src / index.js View on Github external
invert(cb) {
    this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
      x,
      y,
      idx
    ) {
      this.bitmap.data[idx] = 255 - this.bitmap.data[idx];
      this.bitmap.data[idx + 1] = 255 - this.bitmap.data[idx + 1];
      this.bitmap.data[idx + 2] = 255 - this.bitmap.data[idx + 2];
    });

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
});
github oliver-moran / jimp / packages / core / src / index.js View on Github external
jimpEvMethod('clone', 'clone', function(cb) {
  const clone = new Jimp(this);

  if (isNodePattern(cb)) {
    cb.call(clone, null, clone);
  }

  return clone;
});
github oliver-moran / jimp / packages / plugin-gaussian / src / index.js View on Github external
blue += this.bitmap.data[idx + 2] * weight;
            alpha += this.bitmap.data[idx + 3] * weight;
            wsum += weight;
          }

          const idx = (y * this.bitmap.width + x) << 2;

          this.bitmap.data[idx] = Math.round(red / wsum);
          this.bitmap.data[idx + 1] = Math.round(green / wsum);
          this.bitmap.data[idx + 2] = Math.round(blue / wsum);
          this.bitmap.data[idx + 3] = Math.round(alpha / wsum);
        }
      }
    }

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
});
github oliver-moran / jimp / packages / plugin-flip / src / index.js View on Github external
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
    x,
    y,
    idx
  ) {
    const _x = horizontal ? this.bitmap.width - 1 - x : x;
    const _y = vertical ? this.bitmap.height - 1 - y : y;
    const _idx = (this.bitmap.width * _y + _x) << 2;
    const data = this.bitmap.data.readUInt32BE(idx);

    bitmap.writeUInt32BE(data, _idx);
  });

  this.bitmap.data = Buffer.from(bitmap);

  if (isNodePattern(cb)) {
    cb.call(this, null, this);
  }

  return this;
}
github oliver-moran / jimp / packages / plugin-mask / src / index.js View on Github external
sy,
      idx
    ) {
      const destX = x + sx;
      const destY = y + sy;

      if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
        const dstIdx = baseImage.getPixelIndex(destX, destY);
        const { data } = this.bitmap;
        const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;

        baseImage.bitmap.data[dstIdx + 3] *= avg / 255;
      }
    });

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
});

@jimp/utils

MIT
Latest version published 8 days ago

Package Health Score

92 / 100
Full package analysis