我有一个图像,并想应用一个水印(另一个图像)在它使用Node.js。要求水印不应该是纯色的图片(我可以使用gm库的draw()),而应该是半透明的。你能建议使用什么工具吗?
发布于 2012-11-09 02:52:06
通过派生子进程从命令行使用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找到一个很棒的模块。
发布于 2014-09-18 18:36:01
你可以将水印图像设置为半透明,然后在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?
});发布于 2015-05-04 12:20:21
我使用代码
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:不符合绘图图元定义`/path/to/half-transparent-watermark-image.png''@ draw.c / DrawImage / 3124
https://stackoverflow.com/questions/13288508
复制相似问题