Add support to withMetadata for custom ICC profile #2271

This commit is contained in:
Robert O'Rourke
2020-06-26 11:24:47 +01:00
committed by Lovell Fuller
parent 05ca7d3129
commit eaecb7347b
12 changed files with 75 additions and 3 deletions

View File

@@ -119,7 +119,8 @@ function toBuffer (options, callback) {
/**
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
* This will also convert to and add a web-friendly sRGB ICC profile.
* This will also convert to and add a web-friendly sRGB ICC profile unless a custom
* output profile is provided.
*
* The default behaviour, when `withMetadata` is not used, is to convert to the device-independent
* sRGB colour space and strip all metadata, including the removal of any ICC profile.
@@ -132,6 +133,7 @@ function toBuffer (options, callback) {
*
* @param {Object} [options]
* @param {number} [options.orientation] value between 1 and 8, used to update the EXIF `Orientation` tag.
* @param {string} [options.icc] filesystem path to output ICC profile, defaults to sRGB.
* @returns {Sharp}
* @throws {Error} Invalid parameters
*/
@@ -145,6 +147,13 @@ function withMetadata (options) {
throw is.invalidParameterError('orientation', 'integer between 1 and 8', options.orientation);
}
}
if (is.defined(options.icc)) {
if (is.string(options.icc)) {
this.options.withMetadataIcc = options.icc;
} else {
throw is.invalidParameterError('icc', 'string filesystem path to ICC profile', options.icc);
}
}
}
return this;
}