Improve detection of jp2 filename extensions #3674

This commit is contained in:
BJJ
2023-05-20 19:12:01 +08:00
committed by Lovell Fuller
parent f5845c7e61
commit 7e6a70af44
2 changed files with 9 additions and 2 deletions

View File

@@ -29,7 +29,7 @@ const formats = new Map([
['jxl', 'jxl']
]);
const jp2Regex = /\.jp[2x]|j2[kc]$/i;
const jp2Regex = /\.(jp[2x]|j2[kc])$/i;
const errJp2Save = () => new Error('JP2 output requires libvips with support for OpenJPEG');
@@ -75,7 +75,7 @@ function toFile (fileOut, callback) {
err = new Error('Missing output file path');
} else if (is.string(this.options.input.file) && path.resolve(this.options.input.file) === path.resolve(fileOut)) {
err = new Error('Cannot use same file for input and output');
} else if (jp2Regex.test(fileOut) && !this.constructor.format.jp2k.output.file) {
} else if (jp2Regex.test(path.extname(fileOut)) && !this.constructor.format.jp2k.output.file) {
err = errJp2Save();
}
if (err) {