首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Node.js中对图像应用半透明水印

在Node.js中对图像应用半透明水印
EN

Stack Overflow用户
提问于 2012-11-08 19:49:12
回答 3查看 7.2K关注 0票数 1

我有一个图像,并想应用一个水印(另一个图像)在它使用Node.js。要求水印不应该是纯色的图片(我可以使用gm库的draw()),而应该是半透明的。你能建议使用什么工具吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-09 02:52:06

通过派生子进程从命令行使用ImageMagick

代码语言:javascript
复制
// 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找到一个很棒的模块。

票数 5
EN

Stack Overflow用户

发布于 2014-09-18 18:36:01

你可以将水印图像设置为半透明,然后在gm中使用:

代码语言:javascript
复制
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?
});
票数 5
EN

Stack Overflow用户

发布于 2015-05-04 12:20:21

我使用代码

代码语言:javascript
复制
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

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13288508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档