mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 03:50:13 +02:00
Fix for orientation values 1-8
This commit is contained in:
parent
c66495b66c
commit
ebfc897bcf
@ -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.
|
||||
|
6
index.js
6
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user