# Node.js GM operator() Function

The **operator() function** is an inbuilt function in the GraphicsMagick library which is used to apply a mathematical, bitwise, or value operator to an image channel. If the result of operations is negative then the result are reset to zero and if the result of operations is an overflow to the available range then the result is set to maximum possible value.**Syntax:**

operator( channel, operator, rvalue[%] )

**Parameters:** This function accept four parameters as mentioned above and described below:

**channel:**This parameter is used to specify the value of channel from Red, Green, Blue, Opacity, Matte, Cyan, Magenta, Yellow, Black, All, or Gray. The channel value**All**modifies the color channels and does not modify the opacity of channel.**operator:**This parameter is used to specify the value of operator.

The list of operators and its descriptions are given below:**Add:**The result of the Add operator gives the rvalue added to channel value.**And:**The result of And operator gives the logical AND of rvalue with channel value.**Assign:**The Assign operator gives the result as rvalue provided.**Depth:**The result of Depth operator gives the channel value adjusted so that it may be (approximately) stored in the specified number of bits without additional loss.**Divide:**The Divide operator gives the result as channel value divided by rvalue.**Gamma:**The Gamma operator gives the result as channel value gamma adjusted by rvalue.**LShift:**The Lshift operator gives the result as channel value bitwise left-shifted by rvalue bits.**Log:**The Log operator gives the result as computed as log(value*rvalue+1)/log(rvalue+1).**Max:**The Max operator gives the result as assigned to rvalue if rvalue is greater than value.**Min:**The Min operator gives the result as assigned to rvalue if rvalue is less than value.**Multiply:**The Multiply operator gives the result as channel value multiplied by rvalue.**Negate:**The Negate operator gives the result as inverse of channel value (like a film negative).**Or:**The OR operator gives the result as the logical OR of rvalue with channel value.**Pow:**The pow operator gives the result as computed as pow(value,rvalue).**Rshift:**The rshift operator gives the result as channel value bitwise right-shifted by rvalue bits.**Subtract:**The subtract operator gives the result as channel value minus rvalue.**Threshold:**The Threshold operator gives the result as maximum (white) if channel value is greater than rvalue, or minimum (black) if it is less than or equal to rvalue.**Threshold-white:**The Threshold-white operator gives the result as maximum (white) if channel value is greater than rvalue and is unchanged if it is less than or equal to rvalue.**Threshold-White-Negate:**The Threshold-white-negate operator gives the result as set to black if channel value is greater than rvalue and is unchanged if it is less than or equal to rvalue.**Threshold-black:**The Threshold-black operator gives the result as a minimum (black) if channel value is less than rvalue and is unchanged if it is greater than or equal to rvalue.**Threshold-Black-Negate:**The Threshold-black-negate operator gives the result as set to white if channel value is less than rvalue and is unchanged if it is greater than or equal to rvalue.**Xor:**The XOR operator gives the result as the logical XOR of rvalue with channel value.**Noise-Gaussian:**The Noise-Gaussian operator gives the result as the current channel value modulated with Gaussian noise according to the intensity specified by rvalue.**Noise-Impulse:**The Noise-Impulse operator gives the result as the current channel value modulated with Impulse noise according to the intensity specified by rvalue.**Noise-Laplacian:**The Noise-Laplacian operator gives the result as the current channel value modulated with Laplacian noise according to the intensity specified by rvalue.**Noise-Multiplicative:**The Noise-Multiplicative operator gives the result as the current channel value modulated with multiplicative Gaussian noise according to the intensity specified by rvalue.**Noise-Poisson:**The Noise-Poisson operator gives the result as the current channel value modulated with Poisson noise according to the intensity specified by rvalue.**Noise-Random:**The Noise-Random operator gives the result as current channel value modulated with random (uniform distribution) noise according to the intensity specified by rvalue.**Noise-Uniform:**The Noise-Uniform operator gives the result as the channel value with uniform noise applied according to the intensity specified by rvalue.

**rvalue:**This parameter is used to specify the value which is in range of floating-point or integer value. Usually, the rvalue will be in the range of 0 to MaxRGB, where MaxRGB is the largest quantum value supported by the GraphicsMagick build (255, 65535, or 4294967295) but values outside this range are useful for some arithmetic operations. The parameter values are rounded to a positive integral value before using it. If we add a percent (%) symbol then the range of argument has 0 to 100.

**Return Value:** This function returns the GraphicsMagick object.**Example 1:**

## javascript

`// Include gm library` `var` `gm = require(` `'gm'` `);` ` ` `// Import the image` `gm(` `'1.png'` `)` ` ` `// Invoke operator function with` `// Channel as 'Green', Operator` `// as 'And' and rValue(%) as 55` `.operator(` `'Green'` `, ` `'And'` `, 55, ` `true` `)` ` ` `// Process and Write the image` `.write(` `"operator-and1.png"` `, ` `function` `(err) {` ` ` `if` `(!err) console.log(` `'done'` `);` `});` |

**Output:**

**Example 2:**

## javascript

`// Include gm library` `var` `gm = require(` `'gm'` `);` ` ` `// Import the image` `gm(` `'1.png'` `)` ` ` `// Invoke operator function with` `// Channel as 'Green', Operator` `// as 'Divide' and rValue(%) as 55` `.operator(` `'Green'` `,` `'Divide'` `,10,` `true` `)` ` ` `// Process and Write the image` `.write(` `"operator-divide1.png"` `, ` `function` `(err) {` ` ` `if` `(!err) console.log(` `'done'` `);` `});` |

**Output:**

**Example 3: **

## javascript

`// Include gm library` `var` `gm = require(` `'gm'` `);` ` ` `// Import the image` `gm(600, 300, ` `'white'` `)` ` ` `// Set the color for the stroke` `.stroke(` `"green"` `, 3)` ` ` `// Set the font ` `.font(` `"Helvetica.ttf"` `, 60)` ` ` `// Call to drawText Function` `.drawText(100, 280, ` `"GeeksforGeeks!"` `)` ` ` `// Invoke operator function with` `// Channel as 'Green', Operator as` `// 'Assign' and rValue(%) as 35` `.operator(` `'Green'` `, ` `'Assign'` `, 35, ` `true` `)` ` ` `// Process and write the image ` `.write(` `"operator-assign2.png"` `, ` `function` `(err) {` ` ` `if` `(!err) console.log(` `'done'` `);` `});` |

**Output:**

**Reference:**