Fix for orientation values 1-8

This commit is contained in:
John Tobin 2016-03-25 18:29:53 -07:00 committed by Lovell Fuller
parent c66495b66c
commit ebfc897bcf
3 changed files with 10 additions and 5 deletions

View File

@ -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.

View File

@ -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);
}
}
}

View File

@ -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});
});
});
});