mirror of
https://github.com/lovell/sharp.git
synced 2025-07-11 03:20:13 +02:00
Allow use of heic/heif identifiers with toFormat (#1834)
This commit is contained in:
parent
0778c112a9
commit
5bfcf61a6f
@ -487,6 +487,17 @@ function raw () {
|
||||
return this._updateFormatOut('raw');
|
||||
}
|
||||
|
||||
const formats = new Map([
|
||||
['heic', 'heif'],
|
||||
['heif', 'heif'],
|
||||
['jpeg', 'jpeg'],
|
||||
['jpg', 'jpeg'],
|
||||
['png', 'png'],
|
||||
['raw', 'raw'],
|
||||
['tiff', 'tiff'],
|
||||
['webp', 'webp']
|
||||
]);
|
||||
|
||||
/**
|
||||
* Force output to a given format.
|
||||
*
|
||||
@ -502,14 +513,11 @@ function raw () {
|
||||
* @throws {Error} unsupported format or options
|
||||
*/
|
||||
function toFormat (format, options) {
|
||||
if (is.object(format) && is.string(format.id)) {
|
||||
format = format.id;
|
||||
const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
|
||||
if (!actualFormat) {
|
||||
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(`, `)}`, format);
|
||||
}
|
||||
if (format === 'jpg') format = 'jpeg';
|
||||
if (!is.inArray(format, ['jpeg', 'png', 'webp', 'tiff', 'raw'])) {
|
||||
throw is.invalidParameterError('format', 'one of: jpeg, png, webp, tiff, raw', format);
|
||||
}
|
||||
return this[format](options);
|
||||
return this[actualFormat](options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user