123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 'use strict';
- const is = require('./is');
- const bool = {
- and: 'and',
- or: 'or',
- eor: 'eor'
- };
- function removeAlpha () {
- this.options.removeAlpha = true;
- return this;
- }
- function ensureAlpha (alpha) {
- if (is.defined(alpha)) {
- if (is.number(alpha) && is.inRange(alpha, 0, 1)) {
- this.options.ensureAlpha = alpha;
- } else {
- throw is.invalidParameterError('alpha', 'number between 0 and 1', alpha);
- }
- } else {
- this.options.ensureAlpha = 1;
- }
- return this;
- }
- function extractChannel (channel) {
- const channelMap = { red: 0, green: 1, blue: 2, alpha: 3 };
- if (Object.keys(channelMap).includes(channel)) {
- channel = channelMap[channel];
- }
- if (is.integer(channel) && is.inRange(channel, 0, 4)) {
- this.options.extractChannel = channel;
- } else {
- throw is.invalidParameterError('channel', 'integer or one of: red, green, blue, alpha', channel);
- }
- return this;
- }
- function joinChannel (images, options) {
- if (Array.isArray(images)) {
- images.forEach(function (image) {
- this.options.joinChannelIn.push(this._createInputDescriptor(image, options));
- }, this);
- } else {
- this.options.joinChannelIn.push(this._createInputDescriptor(images, options));
- }
- return this;
- }
- function bandbool (boolOp) {
- if (is.string(boolOp) && is.inArray(boolOp, ['and', 'or', 'eor'])) {
- this.options.bandBoolOp = boolOp;
- } else {
- throw is.invalidParameterError('boolOp', 'one of: and, or, eor', boolOp);
- }
- return this;
- }
- module.exports = function (Sharp) {
- Object.assign(Sharp.prototype, {
-
- removeAlpha,
- ensureAlpha,
- extractChannel,
- joinChannel,
- bandbool
- });
-
- Sharp.bool = bool;
- };
|