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
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 61ed2be commit e76d030
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 e76d030

Please sign in to comment.