about summary refs log tree commit diff
path: root/app/javascript/flavours
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-08-06 12:08:19 +0200
committerThibaut Girka <thib@sitedethib.com>2019-08-06 15:09:30 +0200
commit381dbb6569b07554a2543082cbb2e736fb425e2a (patch)
tree806bca9af0b8747f0917498d152f418465f4dea8 /app/javascript/flavours
parenta4b15e2cf063666262e1caab7d213d7ec9d2b67b (diff)
[Glitch] Fix image uploads being perfectly white when canvas read access is blocked
Port 111a0628fc161df4d76967d7dc7116b8a43fe8e2 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours')
-rw-r--r--app/javascript/flavours/glitch/util/resize_image.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/util/resize_image.js b/app/javascript/flavours/glitch/util/resize_image.js
index bbdbc865e..a8ec5f3fa 100644
--- a/app/javascript/flavours/glitch/util/resize_image.js
+++ b/app/javascript/flavours/glitch/util/resize_image.js
@@ -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);
 });