write()函数是GraphicsMagick库中的内置函数,用于将图像写入文件。如果文件已经存在,则它将被覆盖。成功时该函数返回真实值。
用法:
write( filename )
参数:该函数接受上述和以下描述的单个参数:
- filename:此参数用于指定文件名。
返回值:此函数返回GraphicsMagick对象。
范例1:
// 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)
// Invoke drawRectangle function with
// x0:10, y0:100, x1:260, y1:210
.drawRectangle(10, 100, 260, 210)
// Invoke drawText in order to
// name the box as 1
.drawText(150, 170, "1")
// Invoke drawrectangle function with
// x0:260, y0:100, x1:350, y1:210
.drawRectangle(260, 100, 350, 210)
// Invoke drawText in order to
// name the box as 2
.drawText(300, 170, "2")
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Process and write the image
.write("drawRectangle1.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)
// Invoke drawRectangle function with
// x0:10, y0:100, x1:260, y1:210,
// wc:40, wh:40
.drawRectangle(10, 100, 260, 210, 40, 40)
// Invoke drawText in order to
// name the box as 1
.drawText(150, 170, "1")
// Invoke drawrectangle function with
// x0:260, y0:100, x1:350, y1:210,
// wc:80, wh:80
.drawRectangle(260, 100, 350, 210, 80, 80)
// Invoke drawText in order to
// name the box as 2
.drawText(300, 170, "2")
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Process and write the image
.write("drawRectangle1.png", function (err) {
if (!err) console.log('done');
});
输出:
参考: https://www.npmjs.com/package/gm
相关用法
- Node.js GM drawPolyline()用法及代码示例
- Node.js GM threshold()用法及代码示例
- Node.js GM drawBezier()用法及代码示例
- Node.js GM thumbnail()用法及代码示例
- Node.js GM drawArc()用法及代码示例
- Node.js GM magnify()用法及代码示例
- Node.js GM minify()用法及代码示例
- Node.js GM drawLine()用法及代码示例
- Node.js GM whiteThreshold()用法及代码示例
- Node.js GM whitePoint()用法及代码示例
- Node.js GM drawCircle()用法及代码示例
- Node.js GM drawPolygon()用法及代码示例
- Node.js GM drawRectangle()用法及代码示例
- Node.js GM transparent()用法及代码示例
注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 Nodejs | GM write() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。