FIX: Handle image decoding failure in composer image optimization (#13555)

There are some hard limits in browser Canvas implementations, that will
throw a runtime exception when crossed. Since those limits are platform
dependent, the best we can do is catch it and back off from trying to
optimize a problematic file.

For example, a 60MB PNG can be processed fine by Chrome but Firefox will
fail trying to extract the ImageData from the CanvasRenderingContext2D
with NS_ERROR_FAILURE.

Also cleans up the media-optimization-utils and add post-resize size logs
This commit is contained in:
Rafael dos Santos Silva
2021-06-28 18:21:39 -03:00
committed by GitHub
parent d03aee4642
commit 99da221034
3 changed files with 40 additions and 25 deletions

View File

@ -81,6 +81,7 @@ async function optimize(imageData, fileName, width, height, settings) {
).data;
width = target_dimensions.width;
height = target_dimensions.height;
logIfDebug(`Worker post resizing file: ${maybeResized.byteLength}`);
} catch (error) {
console.error(`Resize failed: ${error}`);
maybeResized = imageData;