Search code examples
imagemagickelectrongraphicsmagick

How do you install and bundle GraphicsMagick in an Electron app?


I'm building an electron app and I need GraphicsMagick. The documentation suggest that you have to download and install the program itself before using it with node.js. So just installing the npm package is not enough.

How do I do it then? Do I actually have to have my Electron app download binaries (or bundle it with binaries) and then install the program on the first app launch in order to be able to use it?

It doesn't even support CLI commands like for example ffmpeg does, so I cannot just bundle the binaries and execute commands like gm.exe convert test.jpg


Solution

  • I'd say yes, you have to bundle the binaries together with your app, if you don't want to distribute your app via a package repository or require your user to install GraphicsMagick previously.

    It does support CLI commands like gm.exe convert test.jpg. If your using electron-builder for packaging, you must add a configuration to prevent the binaries from being asar-packed:

      "build": {
        "asarUnpack": [
          "path/to/your/GraphicsMagick/binary/**"
        ],
    

    From electron you can call the program e.g. with

    const child_process = require('child_process')
    child_process.execFile('relative/path/to/your/gm.exe', ['version'], 
     (error, stdout, stderr) => { 
       console.log(stdout) 
     } )
    

    You can download the windows binaries e.g. from the sourceforge host. After installing those binaries you have to copy the installed folder to your app.