我有一个图像,想使用node.js上的水印(另一个图像)应用。要求是水印不应该是扎实的图片(我可以用GM Library的绘图()),而是一半透明。您可以建议使用任何工具吗?
通过分配儿童过程
使用命令行中的ImageMagick// Require our module dependencies
var exec = require('child_process').exec;
// Create command array to invoke ImageMagick composite where
// -dissolve is the amount of transparency for the watermark
// -gravity tells how to align images of varying size
// -quality is the image quality of the JPEG (not required if producing PNG)
var command = [
'composite',
'-dissolve', '50%',
'-gravity', 'center',
'-quality', 100,
'/path/to/watermark.png',
'/path/to/image.jpg',
'/path/to/save/result.jpg';
];
// Join command array by a space character and then execute command
exec(command.join(' '), function(err, stdout, stderr) {
// Do stuff with result here
});
如果您需要API抽象,请在此处找到一个很棒的模块https://github.com/rsms/node-imagemagick
您可以使水印图像半透明剂,并与GM一起使用:
gm('/path/to/input-image.jpg')
.draw(['image Over 0,0 0,0 /path/to/half-transparent-watermark-image.png'])
.write('/path/to/output-image.jpg', function(e){
console.log(e||'done'); // What would you like to do here?
});
我使用代码
gm('/path/to/input-image.jpg')
.draw(['image Over 0,0 0,0 /path/to/half-transparent-watermark-image.png'])
.write('/path/to/output-image.jpg', function(e){
console.log(e||'done'); // What would you like to do here?
});
错误:命令失败:convert:不合格绘制绘制原始定义