A platform for community discussion. Free, open, simple.
FIX: Image optimization error when re-encoding to JPEG (#36039)
Martin Brennan66cee823ab1f
diff --git a/frontend/discourse/app/static/media-optimization-bundle.js b/frontend/discourse/app/static/media-optimization-bundle.jsindex 9c7e0328e0d..5358d8656e8 100644--- a/frontend/discourse/app/static/media-optimization-bundle.js+++ b/frontend/discourse/app/static/media-optimization-bundle.js@@ -77,7 +77,7 @@ globalThis.optimize = async function (// resizeif (width > settings.resize_threshold) {try {- const target_dimensions = resizeWithAspect(+ const targetDimensions = resizeWithAspect(width,height,settings.resize_target@@ -88,8 +88,8 @@ globalThis.optimize = async function (height);const resizeResult = await resize(wrappedImageData, {- width: target_dimensions.width,- height: target_dimensions.height,+ width: targetDimensions.width,+ height: targetDimensions.height,method: "lanczos3",premultiply: settings.resize_pre_multiply,linearRGB: settings.resize_linear_rgb,@@ -98,8 +98,8 @@ globalThis.optimize = async function (throw "Image corrupted during resize. Falling back to the original for encode";}maybeResized = resizeResult.data;- width = target_dimensions.width;- height = target_dimensions.height;+ width = targetDimensions.width;+ height = targetDimensions.height;logIfDebug(`Worker post resizing file: ${maybeResized.byteLength}`);} catch (error) {// eslint-disable-next-line no-console@@ -113,7 +113,7 @@ globalThis.optimize = async function (// mozJPEG re-encodeconst result = await encode(- new ImageData(maybeResized, width, height),+ new ImageData(new Uint8ClampedArray(maybeResized), width, height),mozJpegDefaultOptions);