【问题标题】:Merge multiple png images with transparency in node.js在node.js中合并多个具有透明度的png图像
【发布时间】:2014-03-16 18:25:56
【问题描述】:

我使用此代码将多个图像合并为一个,但结果文件中的透明度消失了。背景为纯黑色。

gm.in('convert').in('-size', '200x100')
.in('xc:transparent')
.in('-page', '+0+0').in('image1.png')
.in('-page', '+100+0').in('image1.png')
.in('-flatten')
.write('result.png', function (err) {
    if (err) console.log(err);
})

我也试过了:

.in('background', 'transparent')

.in('background', 'black')
.in('transparency', 'black')

知道怎么做吗?

【问题讨论】:

    标签: node.js png graphicsmagick


    【解决方案1】:

    你可以试试这个..

    gm.in('convert').in('-size', '200x100')
      .in('-page', '+0+0').in('image1.png')
      .in('-page', '+100+0').in('image1.png')
      .in('-background', 'none')
      .write('result.png', function (err) {
         if (err) console.log(err);
      })
    

    【讨论】:

      【解决方案2】:

      http://www.graphicsmagick.org/FAQ.html#how-can-i-add-a-matte-layer-to-my-image

      您需要使用复合命令。

      gm.prototype.compose = function(operator) {
         this.command('composite'); // need to use composite over the node gm default convert
         return this.out("-compose", operator);
      };
      
      
      gm....
      .compose('CopyOpacity').
      

      【讨论】:

      • 在我的例子中,gm 是模块 gm,我通过 npm 安装:gm = require('gm')。错误是 TypeError: Object # has no method 'command'。您使用的是其他库吗?
      • 是的,原型覆盖应该允许您使用“复合”而不是默认值。
      • 我没有得到它的工作,并决定使用 Imagemagic。它对我来说开箱即用。非常感谢您的帮助。
      【解决方案3】:

      对于那些对此讨论感到困惑的人。通用汽车仍在继续开发,但在 github 上有一个分支。发起者未能使 npm 保持最新。只需将最新的 fork 直接 fork 到 node_modules 中即可。

      【讨论】:

      • 你有分叉的链接吗?
      猜你喜欢
      • 2011-10-14
      • 2011-06-02
      • 2014-12-21
      • 2010-12-22
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      相关资源
      最近更新 更多