Skip to content

Commit

Permalink
Fix image uploads being perfectly white when canvas read access is bl…
Browse files Browse the repository at this point in the history
…ocked

Fixes mastodon#11496
  • Loading branch information
ClearlyClaire committed Aug 6, 2019
1 parent 6201bfd commit 4a9df50
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/javascript/mastodon/utils/resize_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 4a9df50

Please sign in to comment.