about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util/resize_image.js
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-08-06 17:25:54 +0200
committerGitHub <noreply@github.com>2019-08-06 17:25:54 +0200
commit8400ddca7155005ab79485ed6054c04ea3ca5667 (patch)
tree696f5ae9a70891e96fdf819905b05aa6482bcf07 /app/javascript/flavours/glitch/util/resize_image.js
parent3ea7a334d89d2c4075b1dbf649d692ff49325f2e (diff)
parentd10f6036cfeebec5b2c160db8659d2c19d29fe9c (diff)
Merge pull request #1191 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours/glitch/util/resize_image.js')
-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);
 });