mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-12 14:16:12 +01:00
[Glitch] Fix image uploads being perfectly white when canvas read access is blocked
Port 111a0628fc
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
This commit is contained in:
parent
a4b15e2cf0
commit
381dbb6569
@ -67,6 +67,14 @@ const processImage = (img, { width, height, orientation, type = 'image/png' }) =
|
||||
|
||||
context.drawImage(img, 0, 0, width, height);
|
||||
|
||||
// The Tor Browser and maybe other browsers may prevent reading from canvas
|
||||
// and return an all-white image instead. Assume reading failed if the resized
|
||||
// image is perfectly white.
|
||||
const imageData = context.getImageData(0, 0, width, height);
|
||||
if (imageData.every(value => value === 255)) {
|
||||
throw 'Failed to read from canvas';
|
||||
}
|
||||
|
||||
canvas.toBlob(resolve, type);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user