From ebfc897bcfa32877f8d4483122bcecf30c464f3f Mon Sep 17 00:00:00 2001 From: John Tobin Date: Fri, 25 Mar 2016 18:29:53 -0700 Subject: [PATCH] Fix for orientation values 1-8 --- docs/api.md | 2 +- index.js | 6 +++--- test/unit/metadata.js | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index e422e012..540f1e24 100644 --- a/docs/api.md +++ b/docs/api.md @@ -519,7 +519,7 @@ This will also convert to and add the latest web-friendly v2 sRGB ICC profile. The optional `metadata` parameter, if present, is an Object with the attributes to update. New attributes cannot be inserted, only existing attributes updated. -* `orientation` is an integral Number between 0 and 7, used to update the value of the EXIF `Orientation` tag. +* `orientation` is an integral Number between 1 and 8, used to update the value of the EXIF `Orientation` tag. This has no effect if the input image does not have an EXIF `Orientation` tag. The default behaviour, when `withMetadata` is not used, is to strip all metadata and convert to the device-independent sRGB colour space. diff --git a/index.js b/index.js index dbb70a48..8becf8d3 100644 --- a/index.js +++ b/index.js @@ -624,12 +624,12 @@ Sharp.prototype.withMetadata = function(withMetadata) { typeof withMetadata.orientation === 'number' && !Number.isNaN(withMetadata.orientation) && withMetadata.orientation % 1 === 0 && - withMetadata.orientation >= 0 && - withMetadata.orientation <= 7 + withMetadata.orientation >= 1 && + withMetadata.orientation <= 8 ) { this.options.withMetadataOrientation = withMetadata.orientation; } else { - throw new Error('Invalid orientation (0 to 7) ' + withMetadata.orientation); + throw new Error('Invalid orientation (1 to 8) ' + withMetadata.orientation); } } } diff --git a/test/unit/metadata.js b/test/unit/metadata.js index 05f9503a..6613a367 100644 --- a/test/unit/metadata.js +++ b/test/unit/metadata.js @@ -337,9 +337,14 @@ describe('Image metadata', function() { sharp().withMetadata({orientation: -1}); }); }); + it('Zero orientation', function () { + assert.throws(function () { + sharp().withMetadata({ orientation: 0 }); + }); + }); it('Too large orientation', function() { assert.throws(function() { - sharp().withMetadata({orientation: 8}); + sharp().withMetadata({orientation: 9}); }); }); });