-
Notifications
You must be signed in to change notification settings - Fork 17
Limit user photo uploads to 512x512 pixels #2004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
With this change I can upload a photo on both the simulated 2G and GPRC throttling in chromium on the PR environment. |
Current coverage is 91.41% (diff: 83.01%)@@ master #2004 diff @@
==========================================
Files 287 287
Lines 20330 20370 +40
Methods 2477 2482 +5
Messages 0 0
Branches 1802 1805 +3
==========================================
+ Hits 18611 18622 +11
- Misses 1690 1715 +25
- Partials 29 33 +4
|
Code looks fine, looking into testing on different browsers |
👍 from me. Phone is more responsive |
Current coverage is 91.53% (diff: 71.42%)@@ master #2004 diff @@
==========================================
Files 289 289
Lines 20411 20414 +3
Methods 2481 2481
Messages 0 0
Branches 1806 1806
==========================================
+ Hits 18684 18686 +2
+ Misses 1698 1695 -3
- Partials 29 33 +4
|
6752416
to
2f569a6
Compare
not working yet on Safari, seems like it's an encoding issue. |
static/js/util/util.js
Outdated
const ctx: any = canvas.getContext("2d"); | ||
ctx.drawImage(img, 0, 0, width, height); | ||
|
||
return canvas.toBlob(saveCallback, 'image/jpeg'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is always using JPEG format. Wouldn't it be better to use whatever format the incoming image had? If the user tries to upload a PNG file, maybe it should stay as a PNG file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to use JPEG because it is a substantial reduction in size over PNG. I merged a change yesterday which switched that over.
025905e
to
28c21db
Compare
237f684
to
260fcb6
Compare
260fcb6
to
7887efa
Compare
7887efa
to
b6043d8
Compare
b7676c3
to
e13a110
Compare
532833b
to
055fee1
Compare
055fee1
to
8e5acde
Compare
@noisecapella this is ready for further review, and things are working on iOS. The PNG option you suggested didn't pan out, so what I ended up doing is just not attempting to do any resizing on safari or iOS. |
Ugh. Doesn't that defeat the purpose -- especially on iOS? |
Yes, but I could not find a way to make it work. |
height: 512, | ||
}); | ||
} | ||
canvas.toBlob(blob => updatePhotoEdit(blob), 'image/jpeg'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to check for toBlob
here. Will it always exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we have a polyfill for it.
If the image is small this will increase the size to 512x512. That might be fine but just wanted to bring it up IE Chrome, Firefox, and Chrome on Android all work. Can someone do a final test for OS X and iOS? |
It works on my iPhone, not sure about Safari (on macOS I mean). @giocalitri would you mind testing to see if you can upload a profile image on the PR build? |
it works on Safari on Mac OS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This limits the profile image size on the client, by scaling down the canvas used in the `<Cropper />`. This doesn't work on Safari and on iOS, so on those platforms we just upload the image as-is. pr #2004
f7491c4
to
152f2f4
Compare
What are the relevant tickets?
What's this PR do?
This implements a function that uses
<canvas>
to limit the maximum dimensions of user photos to 1024x1024 (right now, we can use whatever number we want).Where should the reviewer start?
How should this be manually tested?
Probably just ensure that even if you throttle your connection it is possible to upload an image? hopefully...
Any background context you want to provide?
Screenshots (if appropriate)
What GIF best describes this PR or how it makes you feel?