I'm fairly new to Grunt, so this might be quite a basic question. I've got a Gruntfile.js that looks like this:
/*global module:false*/
module.exports = function (grunt) {
grunt.initConfig({
});
grunt.registerTask('default', 'measureText');
grunt.registerTask('measureText', 'Measures size of text', function() {
grunt.log.writeln('========================================================================');
grunt.log.writeln('= output of ImageMagick should be on next line: =');
var im = require("node-imagemagick");
im.identify(['-format', '%wx%h', 'build/text.png'], function(err, output){
if (err) throw err;
console.log('dimension: '+output); // <-- NOTHING WRITTEN!
});
grunt.log.writeln('========================================================================');
return;
});
};
As you can see, it's calling the node-imagemagick method identify to get the width and height of an image (build/text.png). When I run my grunt script above, there is no output from the identify() callback. (That's the console.log line above).
Yet if I create a Node script (e.g. test-node-imagemagick.js) to test that same code, it works just fine, e.g.
#!/usr/bin/env node
var im = require("node-imagemagick");
im.identify(['-format', '%wx%h', 'build/text.png'], function(err, output){
if (err) throw err;
console.log('dimension: '+output);
});
So how do I call Node packages from within Grunt tasks, and get returned values?
By the way, I did install the package by doing:
$ npm install node-imagemagick
... from the directory that contains the Gruntfile.js.
Thanks!