forked from musubu/node-ghostscript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
71 lines (55 loc) · 1.43 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var exec = require('child_process').exec;
var create = function() {
return new gs();
};
var gs = function() {
this.options = [];
this._input = null;
};
gs.prototype.batch = function() {
this.options.push('-dBATCH');
return this;
};
gs.prototype.device = function(device) {
device = device || 'jpeg';
this.options.push('-sDEVICE=' + device);
return this;
};
gs.prototype.exec = function(callback) {
var self = this;
if (!this._input) return callback("Please specify input");
var args = this.options.concat([this._input]).join(' ');
exec('gs -dLastPage=1 ' + args, function(err, stdout, stderr) {
callback(err, stdout, stderr);
});
};
gs.prototype.input = function(file) {
this._input = file;
return this;
};
gs.prototype.jpegq = function(value) {
value = value || 75;
this.options.push('-dJPEGQ=' + value);
return this;
};
gs.prototype.nopause = function() {
this.options.push('-dNOPAUSE');
return this;
};
gs.prototype.output = function(file) {
file = file || '-';
this.options.push('-sOutputFile=' + file);
if (file === '-') return this.quiet();
return this;
};
gs.prototype.q = gs.prototype.quiet;
gs.prototype.quiet = function() {
this.options.push('-dQUIET');
return this;
};
gs.prototype.resolution = function(xres, yres) {
this.options.push('-r' + xres + (yres ? 'x' + yres : ''));
return this;
};
gs.prototype.r = gs.prototype.res = gs.prototype.resolution;
module.exports = create;