Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/autoOrient' of git://github.com/kainosnoema/gm …
…into integration Resolved Conflicts: lib/command.js lib/getters.js
- Loading branch information
Showing
8 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed) | ||
|
||
/** | ||
* Extend proto. | ||
*/ | ||
|
||
module.exports = function (proto) { | ||
|
||
var exifTransforms = { | ||
topleft: '' | ||
, topright: ['-flip', 'horizontal'] | ||
, bottomright: ['-rotate', 180] | ||
, bottomleft: ['-flip', 'vertical' ] | ||
, lefttop: ['-transpose'] | ||
, righttop: ['-rotate', 90] | ||
, rightbottom: ['-transverse'] | ||
, leftbottom: ['-rotate', 270] | ||
} | ||
|
||
proto.autoOrient = function autoOrient () { | ||
var self = this; | ||
self.preprocessor(function(callback) { | ||
self.orientation({bufferStream: true}, function (err, orientation) { | ||
if (err) return callback(err); | ||
|
||
var transforms = exifTransforms[orientation.toLowerCase()]; | ||
if(transforms) { | ||
|
||
// remove any existing transforms that might conflict | ||
var index = self._out.indexOf(transforms[0]); | ||
if (~index) { | ||
self._out.splice(index, transforms.length); | ||
} | ||
|
||
// repage to fix coordinates and strip the EXIF | ||
// profile since we can't reset Orientation=1 | ||
var adjustments = []; | ||
adjustments.push('-page', '+0+0'); | ||
adjustments.push('+profile', '"*"'); | ||
|
||
self._out.unshift.apply(self._out, transforms.concat(adjustments)); | ||
|
||
} | ||
|
||
callback(self); | ||
}); | ||
}); | ||
|
||
return self; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed) | ||
|
||
module.exports = function (_, dir, finish, gm) { | ||
|
||
// 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(dir + '/originalSideways.jpg') | ||
.autoOrient() | ||
.write(dir + '/autoOrient.jpg', function autoOrient (err) { | ||
finish(err); | ||
}); | ||
} |