Pregunta

I am creating an image processing API. I have written an example to compute the FFT on an image. This example runs locally but fails (no error, but no output) on Heroku.

My suspicion is that my code require ImageMagick to be installed with FFTW. Is there any way to do it on Heroku? Or wil I forced to find a new provider for my app

var gm = require('gm').subClass({ imageMagick: true });
var im = require('imagemagick');
exports['fft'] = function (req, res, next) {
  var image = __dirname + '/' + req.query.image;
  var image_out = __dirname + '/tmp/output-0.png';
  im.convert([image, '-fft', './tmp/output.png'], function(req, resp, next){
    im.convert([image_out, '-auto-level', '-evaluate', 'log', '100000', './tmp/output-0.png'], function (req1, resp1, next1){
      var base = gm(image_out);
      write(base, res, next);
    });
  });
}
¿Fue útil?

Solución 2

There are a few options; one is to modify the Heroku NodeJS buildpack, and add the necessary scripts to download and compile ImageMagick.

https://devcenter.heroku.com/articles/buildpacks#using-a-custom-buildpack

Secondarily, you could use exec to check for convert or some other part of IM, and run an install script if it isn't present.

  var exec = require('child_process').exec;

  exec('convert', function(error, stdout, stderr) {
    if (error) {
      exec('./install_script', function(error, stdout, stderr) {
        if (!error) {
          initApp();
        }
      });
    } else {
      initApp();
    }
  });

As to the install script, take a look at this link; I'm using it in a grunt task (that compiles on npm install), but I can verify that Heroku will compile it.

In that example, note that I'm not running make install to make the binaries globally available; I'm not sure if that's possible at that point in Heroku's initialization. If not, you could see if node-imagemagick allows you to specify the binary path, or go the buildpack route.

Otros consejos

It's also worth noting and this worked for me:

http://aaronheckmann.tumblr.com/post/48943531250/graphicsmagick-on-heroku-with-nodejs

Simply initializing gm like so:

var gm = require('gm').subClass({
    imageMagick: true
});

Correctly initializes the imagemagick binary installed by heroku.

Than just use gm directly...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top