]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Fix image uploads being perfectly white when canvas read access is blocked
authorThibG <thib@sitedethib.com>
Tue, 6 Aug 2019 10:08:19 +0000 (12:08 +0200)
committerThibaut Girka <thib@sitedethib.com>
Tue, 6 Aug 2019 13:09:30 +0000 (15:09 +0200)
Port 111a0628fc161df4d76967d7dc7116b8a43fe8e2 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/util/resize_image.js

index bbdbc865e9ede08f8ff823c321beb18a7adb4ba1..a8ec5f3fa767286042c9da1084dca64e960584af 100644 (file)
@@ -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);
 });