在Node.js中对图像应用半透明水印 [英] Apply half-transparent watermark to image in Node.js

查看:349
本文介绍了在Node.js中对图像应用半透明水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像,并希望使用Node.js在其上应用水印(另一个图像)。要求是水印不应该是一个坚实的图片(我可以用gm库的绘制()),但一半透明。你可以建议任何使用的工具吗?

I have an image and would like to apply a watermark (another image) over it using Node.js. The requirement is watermark shouldn't be a solid picture (what I can do with gm library's draw()) but half transparent. Can you please advise any tool to use?

推荐答案

使用ImageMagick从命令行分支子进程

Use ImageMagick from the command line by forking a child-process

// 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

If you need an API abstraction, there is a great module found here https://github.com/rsms/node-imagemagick

这篇关于在Node.js中对图像应用半透明水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆