var path = require("path"),
    childProcess = require('child_process'),
    phantomjs = require('phantomjs'),
    fs = require("fs");


module.exports = function(options, html, id, cb) {
    var htmlFilePath = path.resolve(path.join(options.tmpDir, id + ".html"));

    fs.writeFile(htmlFilePath, html, function (err) {
        if (err)
            return cb(err);

        var childArgs = [
            path.join(__dirname, "scripts", "standaloneScript.js"),
            htmlFilePath,
            '--ignore-ssl-errors=yes',
            '--web-security=false',
            '--ssl-protocol=any'
        ];

        var isDone = false;

        var output = "";

        var child = childProcess.execFile(phantomjs.path, childArgs, { maxBuffer: 1024 * 50000 }, function (err, stdout, stderr) {
            if (isDone)
                return;

            isDone = true;
            if (err) {
                return cb(err);
            }

            cb(null, JSON.parse(output));
        });
        child.stdout.on("data", function(data) {
            output += data;
        });

        setTimeout(function() {
            if (isDone)
                return;

            isDone = true;
            cb(new Error("Timeout when executing in phantom"));
        }, options.timeout);
    });
};

var path = require("path"),
    childProcess = require('child_process'),
    phantomjs = require('phantomjs'),
    fs = require("fs");


module.exports = function(options, html, id, cb) {
    var htmlFilePath = path.resolve(path.join(options.tmpDir, id + ".html"));

    fs.writeFile(htmlFilePath, html, function (err) {
        if (err)
            return cb(err);

        var childArgs = [
            path.join(__dirname, "scripts", "standaloneScript.js"),
            htmlFilePath,
            '--ignore-ssl-errors=yes',
            '--web-security=false',
            '--ssl-protocol=any'
        ];

        var isDone = false;

        var output = "";
        var path2PhantomJS = options.phantomJSPath || phantomjs.path;
        var child = childProcess.execFile(path2PhantomJS, childArgs, { maxBuffer: 1024 * 50000 }, function (err, stdout, stderr) {
            if (isDone)
                return;

            isDone = true;
            if (err) {
                return cb(err);
            }

            cb(null, JSON.parse(output));
        });
        child.stdout.on("data", function(data) {
            output += data;
        });

        setTimeout(function() {
            if (isDone)
                return;

            isDone = true;
            cb(new Error("Timeout when executing in phantom"));
        }, options.timeout);
    });
};

Add reference for phantomJSPath option
Add reference for phantomJSPath option

In certain instances, it seems building the phantomjs server the path
to the binary is not always correct and seems to default to /usr/local/bin.
Setting the value exclusively should resolve this.
