节点 | GM randomThreshold()函数
randomThreshold()函数是 GraphicsMagick 库中的一个内置函数,用于将随机阈值应用于图像。该函数在成功时返回真值。
句法:
randomThreshold( channelType, LOWxHIGH )
参数:该函数接受上面提到的两个参数,如下所述:
- channelType:该参数用于指定通道类型的值,为All、Intensity、Red、Green、Blue、Cyan、Magenta、Yellow、Black 和 Opacity 。
- LOWxHIGH:该参数用于指定电平值。阈值永远不会超过指定的最大值 (HIGH) 并且永远不会小于指定的最小值 (LOW)。
返回值:此函数返回 GraphicsMagick 对象。
示例 1:
// Include gm library
var gm = require('gm');
// Import the image
gm('1.png')
// Invoke randomThreshold function
// with Channel Type as 'All' and
// lowxhigh as '10x200'
.randomThreshold('All', '10x200')
// Process and Write the image
.write("randomThreshold1.png", function (err) {
if (!err) console.log('done');
});
输出:
示例 2:
// 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 random Threshold function
// with Channel Type as 'Green' and
// lowxhigh as 100x600
.randomThreshold('Green', '100x600')
// Process and write the image
.write("randomThreshold2.png", function (err) {
if (!err) console.log('done');
});
输出:
参考:
- http://www.graphicsmagick.org/GraphicsMagick.html#details-randomThreshold
- https://www.npmjs.com/package/gm