forked from Imanrabet/gm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoOrientStream.js
43 lines (33 loc) · 1.31 KB
/
autoOrientStream.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
// gm - Copyright Aaron Heckmann <[email protected]> (MIT Licensed)
// This is a copy of `autoOrient.js` using streams
const assert = require('assert')
const fs = require('fs')
const path = require('path');
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration)
return finish();
const filename = path.join(dir, 'autoOrientStream.jpg');
const sidewaysPathName = path.join(dir, 'originalSideways.jpg');
gm(fs.createReadStream(sidewaysPathName)).options({imageMagick}).identify(function (err) {
if (err) return finish(err);
const geo = imageMagick ? '155x460+0+0' : '155x460';
assert.equal(geo, this.data.Geometry);
// this image is sideways, but may be auto-oriented by modern OS's
// try opening it in a browser to see its true orientation
gm(fs.createReadStream(sidewaysPathName))
.options({imageMagick})
.autoOrient()
.write(filename, function autoOrient (err) {
if (err) return finish(err);
// fs race condition
setTimeout(function () {
gm(filename).options({imageMagick}).identify(function (err) {
if (err) return finish(err);
const geo2 = imageMagick ? '460x155+0+0' : '460x155';
assert.equal(geo2, this.data.Geometry);
finish(err);
});
}, 200);
});
});
}