Node.js GM quality()函数
quality()函数是 GraphicsMagick 库中的一个内置函数,用于 JPEG/MIFF/PNG/TIFF 压缩级别。如果 filter-type 为 4 或更少,则指定的 filter-type 用于所有扫描线:0:无,1:sub,2:up,3:average,4:Path。该函数在成功时返回真值。
句法:
quality( level )
参数:此函数接受上面提到并定义如下的单个参数:
- level:此参数用于指定质量的级别。
返回值:此函数返回 GraphicsMagick 对象。
示例 1:
javascript
// Include gm library
var gm = require('gm');
// Import the image
gm('1.png')
// Invoke quality function with
// average parameter
.quality(3)
// Process and Write the image
.write("quality1.png", function (err) {
if (!err) console.log('done');
});
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 quality function with
// sub-option via 1
// 0: none
// 1: sub
// 2: up
// 3: average
// 4: Paeth
.quality(1)
// Process and write the image
.write("quality2.png", function (err) {
if (!err) console.log('done');
});
输出:
示例 2:
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 quality function with
// sub-option via 1
// 0: none
// 1: sub
// 2: up
// 3: average
// 4: Paeth
.quality(1)
// Process and write the image
.write("quality2.png", function (err) {
if (!err) console.log('done');
});
输出:
参考:
- http://www.graphicsmagick.org/GraphicsMagick.html#details-quality
- https://www.npmjs.com/package/gm