Allow use of heic/heif identifiers with toFormat (#1834)

This commit is contained in:
Julian Aubourg 2019-08-12 22:36:56 +02:00 committed by Lovell Fuller
parent 0778c112a9
commit 5bfcf61a6f

View File

@ -487,6 +487,17 @@ function raw () {
return this._updateFormatOut('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. * Force output to a given format.
* *
@ -502,14 +513,11 @@ function raw () {
* @throws {Error} unsupported format or options * @throws {Error} unsupported format or options
*/ */
function toFormat (format, options) { function toFormat (format, options) {
if (is.object(format) && is.string(format.id)) { const actualFormat = formats.get(is.object(format) && is.string(format.id) ? format.id : format);
format = format.id; if (!actualFormat) {
throw is.invalidParameterError('format', `one of: ${[...formats.keys()].join(`, `)}`, format);
} }
if (format === 'jpg') format = 'jpeg'; return this[actualFormat](options);
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);
} }
/** /**