summaryrefslogtreecommitdiffstats
path: root/lib/utils/images.js
blob: 61a52dc24f1f562f6ce15a83267e15f6352682d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var _ = require("lodash");
var Q = require("q");
var fs = require("./fs");
var exec = require('child_process').exec;

var links = require("./links");

// Convert a svg file
var convertSVG = function(source, dest, options) {
	if (!fs.existsSync(source)) return Q.reject(new Error("File doesn't exist: "+source));

	var d = Q.defer();

	options = _.defaults(options || {}, {

	});

	var command = "svgexport "+source+" "+dest;

    var child = exec(command, function (error, stdout, stderr) {
        if (error) {
        	if (error.code == 127) error = new Error("Need to install 'svgexport' using 'npm install svgexport -g'");
        	return d.reject(error);
        }
        d.resolve();
    });

	return d.promise;
};

module.exports = {
	convertSVG: convertSVG,
	INVALID: [".svg"]
};