Fixed autoOrient to work with all types of exif orientations.

master
Luc Castera 12 years ago committed by Aaron Heckmann
parent d58668504d
commit c97679e0ec
  1. 2
      .gitignore
  2. BIN
      examples/imgs/orientation/Landscape_1.jpg
  3. BIN
      examples/imgs/orientation/Landscape_2.jpg
  4. BIN
      examples/imgs/orientation/Landscape_3.jpg
  5. BIN
      examples/imgs/orientation/Landscape_4.jpg
  6. BIN
      examples/imgs/orientation/Landscape_5.jpg
  7. BIN
      examples/imgs/orientation/Landscape_6.jpg
  8. BIN
      examples/imgs/orientation/Landscape_7.jpg
  9. BIN
      examples/imgs/orientation/Landscape_8.jpg
  10. BIN
      examples/imgs/orientation/Portrait_1.jpg
  11. BIN
      examples/imgs/orientation/Portrait_2.jpg
  12. BIN
      examples/imgs/orientation/Portrait_3.jpg
  13. BIN
      examples/imgs/orientation/Portrait_4.jpg
  14. BIN
      examples/imgs/orientation/Portrait_5.jpg
  15. BIN
      examples/imgs/orientation/Portrait_6.jpg
  16. BIN
      examples/imgs/orientation/Portrait_7.jpg
  17. BIN
      examples/imgs/orientation/Portrait_8.jpg
  18. 8
      lib/convenience/autoOrient.js
  19. 100
      test/autoOrientAll.js

2
.gitignore vendored

@ -1,3 +1,4 @@
.DS_Store
node_modules
examples/imgs/*
!examples/imgs/original.jpg
@ -6,5 +7,6 @@ examples/imgs/*
!examples/imgs/originalSideways.jpg
!examples/imgs/morpher.jpg
!examples/imgs/photo.JPG
!examples/imgs/orientation
*.swp
*.swo

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

@ -9,12 +9,12 @@ module.exports = function (proto) {
var exifTransforms = {
topleft: ''
, topright: ['-flip', 'horizontal']
, topright: ['-flop']
, bottomright: ['-rotate', 180]
, bottomleft: ['-flip', 'vertical' ]
, lefttop: ['-transpose']
, bottomleft: ['-flip']
, lefttop: ['-flip', '-rotate', 90]
, righttop: ['-rotate', 90]
, rightbottom: ['-transverse']
, rightbottom: ['-flop', '-rotate', 90]
, leftbottom: ['-rotate', 270]
}

@ -0,0 +1,100 @@
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
var assert = require('assert'),
fs = require('fs');
module.exports = function (_, dir, finish, gm) {
var filename = dir + '/autoOrient.jpg';
var beforeValues = {
'Landscape_1.jpg': ['TopLeft', 1, '600x450'],
'Landscape_2.jpg': ['TopRight', 2, '600x450'],
'Landscape_3.jpg': ['BottomRight', 3, '600x450'],
'Landscape_4.jpg': ['BottomLeft', 4, '600x450'],
'Landscape_5.jpg': ['LeftTop', 5, '450x600'],
'Landscape_6.jpg': ['RightTop', 6, '450x600'],
'Landscape_7.jpg': ['RightBottom', 7, '450x600'],
'Landscape_8.jpg': ['LeftBottom', 8, '450x600'],
'Portrait_1.jpg': ['TopLeft', 1, '450x600'],
'Portrait_2.jpg': ['TopRight', 2, '450x600'],
'Portrait_3.jpg': ['BottomRight', 3, '450x600'],
'Portrait_4.jpg': ['BottomLeft', 4, '450x600'],
'Portrait_5.jpg': ['LeftTop', 5, '600x450'],
'Portrait_6.jpg': ['RightTop', 6, '600x450'],
'Portrait_7.jpg': ['RightBottom', 7, '600x450'],
'Portrait_8.jpg': ['LeftBottom', 8, '600x450']
};
var afterValues = {
'Landscape_1.jpg': ['TopLeft', false, '600x450'],
'Landscape_2.jpg': ['Unknown', true, '600x450'],
'Landscape_3.jpg': ['Unknown', true, '600x450'],
'Landscape_4.jpg': ['Unknown', true, '600x450'],
'Landscape_5.jpg': ['Unknown', true, '600x450'],
'Landscape_6.jpg': ['Unknown', true, '600x450'],
'Landscape_7.jpg': ['Unknown', true, '600x450'],
'Landscape_8.jpg': ['Unknown', true, '600x450'],
'Portrait_1.jpg': ['TopLeft', false, '450x600'],
'Portrait_2.jpg': ['Unknown', true, '450x600'],
'Portrait_3.jpg': ['Unknown', true, '450x600'],
'Portrait_4.jpg': ['Unknown', true, '450x600'],
'Portrait_5.jpg': ['Unknown', true, '450x600'],
'Portrait_6.jpg': ['Unknown', true, '450x600'],
'Portrait_7.jpg': ['Unknown', true, '450x600'],
'Portrait_8.jpg': ['Unknown', true, '450x600']
};
fs.readdir(dir + '/orientation/', function(err, files) {
if (err) return finish(err);
var originalFiles = files.filter(function(file) {
if (/\.oriented\.jpg$/.test(file)) {
return false;
} else {
return true;
}
});
var count = originalFiles.length;
originalFiles.forEach(function(filename, index) {
var fileToAutoOrient = dir + '/orientation/' + filename;
var newFilename = fileToAutoOrient + '.oriented.jpg';
gm(fileToAutoOrient).orientation(function (err, o) {
if (err) return finish(err);
assert.equal(beforeValues[filename][0], o);
assert.equal(beforeValues[filename][1], this.data['Profile-EXIF'].Orientation, 'No Profile-EXIF data found');
assert.equal(beforeValues[filename][2], 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(fileToAutoOrient)
.autoOrient()
.write(newFilename, function autoOrient (err) {
if (err) return finish(err);
// fs race condition
setTimeout(function () {
gm(newFilename).identify(function (err) {
if (err) return finish(err);
assert.equal(afterValues[filename][0], this.data.Orientation, 'Bad-Orientation for ' + filename);
assert.equal(afterValues[filename][1], !this.data['Profile-EXIF'], 'Profile-EXIF still exists');
assert.equal(afterValues[filename][2], this.data.Geometry, 'Bad-Geometry for ' + filename);
count = count - 1;
if (count === 0) {
finish(err);
}
});
}, 500);
});
});
});
});
};
Loading…
Cancel
Save