Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 9071914

Browse files
author
Hans Kristian Flaatten
committed
Auto-orient rotated images
1 parent e55912f commit 9071914

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

assets/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
autorotate-*
12
vertical-*
23
horizontal-*
34
transparent-*

assets/autorotate.jpg

2.62 MB
Loading

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports.path = function(src, opts) {
6969
*/
7070
module.exports.cmd = function(image, output) {
7171
var cmd = [
72-
sprintf('convert %s -strip -write mpr:%s +delete', image.path, image.path)
72+
sprintf('convert %s -auto-orient -strip -write mpr:%s +delete', image.path, image.path)
7373
];
7474

7575
for (var i = 0; i < output.versions.length; i++) {

test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*jshint laxbreak:true */
22

33
var assert = require('assert');
4+
var crypto = require('crypto');
5+
var fs = require('fs');
46
var resize = require('./index');
57

68
describe('resize.path()', function() {
@@ -143,6 +145,7 @@ describe('resize.cmd()', function() {
143145
assert.equal(cmd, [
144146
// original image
145147
'convert ./assets/horizontal.jpg',
148+
'-auto-orient',
146149
'-strip',
147150
'-write mpr:./assets/horizontal.jpg +delete',
148151

@@ -367,4 +370,41 @@ describe('resize()', function() {
367370
done();
368371
});
369372
});
373+
374+
it('auto-rotates rotated image', function(done) {
375+
this.timeout(10000);
376+
377+
var image = {
378+
path: './assets/autorotate.jpg',
379+
width: 3264,
380+
height: 2448
381+
};
382+
383+
var checksum = {
384+
'assets/autorotate-full.jpg' : 'efe10ac17cae71bd28c316728d6d29eeacc11fd8',
385+
'assets/autorotate-1200.jpg' : 'e8f5b75aa6c9859426c1d652d57a053444f897ff',
386+
'assets/autorotate-800.jpg' : '081df1cc1a3d7d76a0762f0d586dbecff221a25c',
387+
'assets/autorotate-500.jpg' : 'c5437d9b2dbbf791931ca9089020c78ac8fd02a3',
388+
'assets/autorotate-260.jpg' : 'a9b811a19fb078264e655c0c3c01acffda8d192e',
389+
'assets/autorotate-150.jpg' : 'd837d5fb4239f9fe1e3566df34906e3f8d654275',
390+
'assets/autorotate-square-200.jpg': '24efb279a78b0c33a8715215d6f976c1f086573a',
391+
'assets/autorotate-square-50.jpg' : 'f716e975f6269c3b9649a04d4144c5481265169c'
392+
};
393+
394+
resize(image, output, function(err, versions) {
395+
assert.ifError(err);
396+
397+
assert(versions instanceof Array);
398+
assert.equal(versions.length, output.versions.length);
399+
400+
for(var i = 0; i < versions.length; i++) {
401+
var file = fs.readFileSync(versions[i].path);
402+
var sha = crypto.createHash('sha1').update(file).digest('hex');
403+
404+
assert.equal(sha, checksum[versions[i].path]);
405+
}
406+
407+
done();
408+
});
409+
});
370410
});

0 commit comments

Comments
 (0)