Skip to content

Conversation

alicewriteswrongs
Copy link
Contributor

@alicewriteswrongs alicewriteswrongs commented Dec 6, 2016

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?

@odlbot odlbot temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 19:21 Inactive
@alicewriteswrongs
Copy link
Contributor Author

With this change I can upload a photo on both the simulated 2G and GPRC throttling in chromium on the PR environment.

@codecov-io
Copy link

codecov-io commented Dec 6, 2016

Current coverage is 91.41% (diff: 83.01%)

Merging #2004 into master will decrease coverage by 0.12%

@@             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   

Powered by Codecov. Last update 32470cd...949e00c

@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 19:48 Inactive
@noisecapella
Copy link
Contributor

Code looks fine, looking into testing on different browsers

@noisecapella
Copy link
Contributor

👍 from me. Phone is more responsive

@codecov-io
Copy link

codecov-io commented Dec 6, 2016

Current coverage is 91.53% (diff: 71.42%)

Merging #2004 into master will decrease coverage by <.01%

@@             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   

Powered by Codecov. Last update 2204c72...f7491c4

@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 20:37 Inactive
@alicewriteswrongs
Copy link
Contributor Author

not working yet on Safari, seems like it's an encoding issue.

const ctx: any = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);

return canvas.toBlob(saveCallback, 'image/jpeg');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 20:59 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 21:20 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 21:39 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 21:42 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 6, 2016 22:22 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 15:35 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 15:54 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 16:24 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 16:36 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 16:47 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 16:54 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 20:26 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 20:27 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 20:36 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 20:51 Inactive
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci-pr-2004 December 7, 2016 20:52 Inactive
@alicewriteswrongs
Copy link
Contributor Author

@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.

@pdpinch
Copy link
Member

pdpinch commented Dec 7, 2016

Ugh. Doesn't that defeat the purpose -- especially on iOS?

@alicewriteswrongs
Copy link
Contributor Author

Yes, but I could not find a way to make it work.

height: 512,
});
}
canvas.toBlob(blob => updatePhotoEdit(blob), 'image/jpeg');
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@noisecapella
Copy link
Contributor

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?

@alicewriteswrongs
Copy link
Contributor Author

alicewriteswrongs commented Dec 9, 2016

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?

@giocalitri
Copy link
Contributor

it works on Safari on Mac OS

Copy link
Contributor

@noisecapella noisecapella left a 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
@alicewriteswrongs alicewriteswrongs merged commit 152f2f4 into master Dec 9, 2016
@alicewriteswrongs alicewriteswrongs deleted the ap/max-file-size branch December 9, 2016 18:32
@alicewriteswrongs alicewriteswrongs temporarily deployed to micromasters-ci December 9, 2016 18:44 Inactive
@pdpinch pdpinch changed the title Limit user photo uploads to 1024x1024 pixels Limit user photo uploads to 512x512 pixels Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants