Skip to content

Commit 4e71128

Browse files
authored
Merge pull request #1 from UniversityofWarwick/SBTWO-12650
SBTWO-12650 Handle buggy JPEGs.
2 parents 8596226 + 9cf9e6c commit 4e71128

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

service.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export async function resize(stream, options) {
1818

1919
// "animated" will read all frames so that GIF files are encoded to animated output
2020
// (where supported, which it is in WebP). For other inputs that are only a single image,
21-
// it has no effect.
22-
let image = sharp({ animated: true }).autoOrient();
21+
// it has no effect. failOn: 'error' allows certain _mildly_ corrupt images to be
22+
// processed rather than sharp failing outright.
23+
let image = sharp({ animated: true, failOn: 'error' }).autoOrient();
2324
const output = stream.pipe(image);
2425
const metadata = await image.metadata();
2526

@@ -108,7 +109,7 @@ export async function analyzeImage(sharpInstance) {
108109
};
109110

110111
} catch (error) {
111-
console.error('Failed to analyze image stats:', error);
112+
logger.error('Failed to analyze image stats:', error);
112113
return {
113114
lossyPreferred: true, // Default to true on error
114115
stats: {

0 commit comments

Comments
 (0)