nodejs图片合成处理,有那些好用的库呢?
发布于 8 年前 作者 suntopo 13372 次浏览 来自 问答

需求: 微信生成的带参数二维码,中间不能添加logo,所以想通过图片合成的方式添加,由于二维码有纠错功能,所以遮挡部分不会有影响.

sharp

但是我看sharp文档中overlaywith方法,必须使用带alpah通道的图片才行.但是一般logo好像都没有alpha,有没有看到sharp添加通道的方法(有知道是哪个的吗?)

imagemagick

我看到node-imagemagick包,但是好像木有封装composite方法(还需要自己在封装下)

这种场景大家用啥子呢

5 回复

https://github.com/aheckmann/gm/blob/master/lib%2Fcomposite.js http://www.graphicsmagick.org/composite.html

/**
 * Composite images together using the `composite` command in graphicsmagick.
 *
 * gm('/path/to/image.jpg')
 * .composite('/path/to/second_image.jpg')
 * .geometry('+100+150')
 * .write('/path/to/composite.png', function(err) {
 *   if(!err) console.log("Written composite image.");
 * });
 *
 * @param {String} other  Path to the image that contains the changes.
 * @param {String} [mask] Path to the image with opacity informtion. Grayscale.
 */

想不到这个库居然是 spawn 实现的

@magicdawn spawn实现有什么不好的地方吗

@suntopo 可能QPS会过低吧~没测过

回到顶部