Skip to content

Commit

Permalink
feat(task): add option autoOrient
Browse files Browse the repository at this point in the history
  • Loading branch information
rangermeier authored and boennemann committed Jan 18, 2015
1 parent e1b0966 commit e0c3b65
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions tasks/image_resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = function(grunt) {
concurrency: os.cpus().length,
crop: false,
gravity: 'Center',
quality: 1
quality: 1,
autoOrient: false
});
var series = [];

Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
Binary file added test/expected/directory/rotate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/expected/rotate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/rotate.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion test/image_resize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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);
}
Expand Down

0 comments on commit e0c3b65

Please sign in to comment.