How to do composite with gm node.js?

前端 未结 6 1262
情话喂你
情话喂你 2020-12-24 08:22

How to do \'gm composite -gravity center change_image_url base_image_url\' with GM Node.js?

How to call gm().command() & gm().in() or <

6条回答
  •  轮回少年
    2020-12-24 09:00

    Having the pleasure of being confined to a windows machine for the moment I solved this problem eventually by not using the "gm" module at all. For some reason, even though I have installed graphics-magick via its installer the node module refused to find it in my environment variables. But that could have something to do with the fact that I am trying to make an application with Electron.js (which is similar to Node.js but has its "gotcha's").

    var exec = require("child_process").execSync;
    var commandArray = [
        __dirname + "/bin/graphicsMagick/gm.exe",    // the relative path to the graphics-magick executable
        "-composite",
        "-gravity",
        "center",
        __dirname + "/data/images/qr/logo-small.png",    // relative paths to the images you want to composite
        __dirname + "/data/images/qr/qr-webpage.png",
        __dirname + "/data/images/qr/qr-webpage-logo.png"    // relative path to the result
    ];
    var returnValue = exec(commandArray.join(" "));
    

    For windows I think this is the correct portable way to do it.

提交回复
热议问题