corrade-nucleus-nucleons – Blame information for rev 36
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
36 | office | 1 | |
2 | /** |
||
3 | * Module dependencies. |
||
4 | */ |
||
5 | |||
6 | var fs = require('fs'); |
||
7 | var parallel = require('array-parallel'); |
||
8 | |||
9 | /** |
||
10 | * Extend proto. |
||
11 | */ |
||
12 | |||
13 | module.exports = function (proto) { |
||
14 | |||
15 | /** |
||
16 | * Do nothing. |
||
17 | */ |
||
18 | |||
19 | function noop () {} |
||
20 | |||
21 | // http://www.graphicsmagick.org/GraphicsMagick.html#details-morph |
||
22 | proto.morph = function morph (other, outname, callback) { |
||
23 | if (!outname) { |
||
24 | throw new Error("an output filename is required"); |
||
25 | } |
||
26 | |||
27 | callback = (callback || noop).bind(this) |
||
28 | |||
29 | var self = this; |
||
30 | |||
31 | if (Array.isArray(other)) { |
||
32 | other.forEach(function (img) { |
||
33 | self.out(img); |
||
34 | }); |
||
35 | self.out("-morph", other.length); |
||
36 | } else { |
||
37 | self.out(other, "-morph", 1); |
||
38 | } |
||
39 | |||
40 | self.write(outname, function (err, stdout, stderr, cmd) { |
||
41 | if (err) return callback(err, stdout, stderr, cmd); |
||
42 | |||
43 | // Apparently some platforms create the following temporary files. |
||
44 | // Check if the output file exists, if it doesn't, then |
||
45 | // work with temporary files. |
||
46 | fs.exists(outname, function (exists) { |
||
47 | if (exists) return callback(null, stdout, stderr, cmd); |
||
48 | |||
49 | parallel([ |
||
50 | fs.unlink.bind(fs, outname + '.0'), |
||
51 | fs.unlink.bind(fs, outname + '.2'), |
||
52 | fs.rename.bind(fs, outname + '.1', outname) |
||
53 | ], function (err) { |
||
54 | callback(err, stdout, stderr, cmd); |
||
55 | }) |
||
56 | }) |
||
57 | }); |
||
58 | |||
59 | return self; |
||
60 | } |
||
61 | } |