forked from aheckmann/gm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoOrientStream.js
41 lines (31 loc) · 1.24 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
// gm - Copyright Aaron Heckmann <[email protected]> (MIT Licensed)
// This is a copy of `autoOrient.js` using streams
var assert = require('assert')
var fs = require('fs')
module.exports = function (_, dir, finish, gm) {
if (!gm.integration)
return finish();
var filename = dir + '/autoOrientStream.jpg';
gm(fs.createReadStream(dir + '/originalSideways.jpg')).orientation(function (err, o) {
if (err) return finish(err);
assert.equal('RightTop', o);
assert.ok(!! this.data['Profile-EXIF'], 'No Profile-EXIF data found');
// 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(dir + '/originalSideways.jpg'))
.autoOrient()
.write(filename, function autoOrient (err) {
if (err) return finish(err);
// fs race condition
setTimeout(function () {
gm(filename).identify(function (err) {
if (err) return finish(err);
assert.equal('Unknown', this.data.Orientation);
assert.ok(! this.data['Profile-EXIF'], 'Profile-EXIF still exists');
assert.equal('460x155', this.data.Geometry);
finish(err);
});
}, 200);
});
});
}