mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
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:

committed by
GitHub

parent
d03aee4642
commit
99da221034
@ -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;
|
||||
|
Reference in New Issue
Block a user