Node.js GM trim()函数
trim()函数是 GraphicsMagick 库中的一个内置函数,用于删除与角像素颜色完全相同的边缘。该函数在成功时返回真值。
句法:
trim()
参数:此函数不接受任何参数。
返回值:此函数返回添加了修剪图像的 GraphicsMagick 对象。
原图:
示例 1:
// Include gm library
var gm = require('gm');
// Import the image
gm('1.png')
// Invoke trim function
.trim()
// Process and Write the image
.write("trim1.png", function (err) {
if (!err) console.log('done');
});
输出:
示例 2:
// Include gm library
var gm = require('gm');
// Import the image
gm('1.png')
// Set stroke color
.stroke("#fe1232")
// Set fill color
.fill("#1200ff")
// Draw Rectangle using drawRectangle function
.drawRectangle(10, 2, 130, 30, 1, 2)
// Invoke wave function with an amplitude
// as 8 and wavelength as 3
.wave(20, 30)
// Invoke trim function
.trim()
// Process and Write the image
.write("trim2.png", function (err) {
if (!err) console.log('done');
});
输出:
参考:
- http://www.graphicsmagick.org/GraphicsMagick.html#details-trim
- https://www.npmjs.com/package/gm