FIX: Detect decode failures earlier in image optimization pipeline (#13595)
* FIX: Detect decode failures earlier in image optimization pipeline
Follow up to 9b51b9b
but also detects the bug earlier and backs off.
What iOS 15 is doing is returning all zeroes to `ctx.getImageData`,
so we don't have to wait until resize to detect the problem.
* Update app/assets/javascripts/discourse/app/lib/media-optimization-utils.js
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
This commit is contained in:
parent
9b51b9bf4e
commit
fae68455b7
|
@ -66,6 +66,14 @@ function isTransparent(type, imageData) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function jpegDecodeFailure(type, imageData) {
|
||||
if (!/(\.|\/)jpe?g$/i.test(type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return imageData.data[3] === 0;
|
||||
}
|
||||
|
||||
export async function fileToImageData(file) {
|
||||
const drawable = await fileToDrawable(file);
|
||||
const imageData = drawableToimageData(drawable);
|
||||
|
@ -74,5 +82,9 @@ export async function fileToImageData(file) {
|
|||
throw "Image has transparent pixels, won't convert to JPEG!";
|
||||
}
|
||||
|
||||
if (jpegDecodeFailure(file.type, imageData)) {
|
||||
throw "JPEG image has transparent pixel, decode failed!";
|
||||
}
|
||||
|
||||
return imageData;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue