diff --git a/Gruntfile.js b/Gruntfile.js index 8342df9..6114a3b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -118,6 +118,16 @@ module.exports = function(grunt) { {'tmp/quality.jpg': 'test/fixtures/quality.jpg'} ] }, + autoOrient: { + options: { + autoOrient: true, + width: 100, + height: 100 + }, + files: [ + {'tmp/rotate.jpg': 'test/fixtures/rotate.jpg'} + ] + }, all: { options: { width: 100, diff --git a/README.md b/README.md index d0a1eb1..cd78363 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,12 @@ Default value: `1` Determines the output quality of the resized image. Ranges from `0` (really bad) to `1` (almost lossless). Only applies to jpg images. +#### options.autoOrient +Type: `Boolean` +Default value: `false` + +Determines if resized image will be rotated according to EXIF information. Only applies to jpg images. + ### Usage Examples #### Default Options diff --git a/tasks/image_resize.js b/tasks/image_resize.js index 11ddce0..57b467c 100644 --- a/tasks/image_resize.js +++ b/tasks/image_resize.js @@ -28,7 +28,8 @@ module.exports = function(grunt) { concurrency: os.cpus().length, crop: false, gravity: 'Center', - quality: 1 + quality: 1, + autoOrient: false }); var series = []; @@ -52,7 +53,8 @@ module.exports = function(grunt) { dstPath: (list.dest[list.dest.length-1] !== '/') ? list.dest : path.join(dirname, path.basename(filepath)) , width: options.width, height: options.height, - quality: options.quality + quality: options.quality, + autoOrient: options.autoOrient }; // Prevent failing if destination directory does not exist. @@ -89,6 +91,10 @@ module.exports = function(grunt) { .resize(imOptions.width, imOptions.height); } + if (options.autoOrient) { + resizer.autoOrient(); + } + resizer .quality(Math.floor(imOptions.quality * 100)) .write(imOptions.dstPath, function(err) { diff --git a/test/expected/directory/rotate.jpg b/test/expected/directory/rotate.jpg new file mode 100644 index 0000000..fada7c2 Binary files /dev/null and b/test/expected/directory/rotate.jpg differ diff --git a/test/expected/rotate.jpg b/test/expected/rotate.jpg new file mode 100644 index 0000000..6213c2d Binary files /dev/null and b/test/expected/rotate.jpg differ diff --git a/test/fixtures/rotate.jpg b/test/fixtures/rotate.jpg new file mode 100644 index 0000000..8aa684a Binary files /dev/null and b/test/fixtures/rotate.jpg differ diff --git a/test/image_resize_test.js b/test/image_resize_test.js index 898c99b..efcbf7e 100644 --- a/test/image_resize_test.js +++ b/test/image_resize_test.js @@ -97,8 +97,13 @@ exports.image_resize = { } ], test.done); }, + autoOrient: function(test) { + test.expect(3); + + createTest(test, "rotate.jpg")(test.done); + }, all: function(test) { - test.expect(27); + test.expect(30); async.series([ createTest(test, "directory/crop.png"), @@ -109,6 +114,7 @@ exports.image_resize = { createTest(test, "directory/TeslaTurbine.png"), createTest(test, "directory/upscale2.png"), createTest(test, "directory/upscale.png"), + createTest(test, "directory/rotate.jpg"), createTest(test, "directory/wikipedia.png") ], test.done); }