CGUC / skybunk-server

The back-end application for Conrad Grebel University College students to stay connected
3 stars 9 forks source link

Image compression #86

Closed scholvat closed 5 years ago

scholvat commented 5 years ago

Script to compress all current images, and code to compress any incoming images.

The big issue with the current setup is the user can upload whatever image they want and we just accept it. This change with convert all images to JPEG which will give much better compression and minor loss. This change reduced the database size of both profile pictures and post pictures collections by almost 10x (see data below). This will also add additional error checking to make sure the user is uploading a valid image. Profile pictures will be resized to 400x400, and post pictures will be 600x600.

issue #79 .

Data acquired from downloading production data, then running db.stats().size for the 2 collections. original size { profilePictures: 49,096,333 postPictures: 106,412,148 } final size { profilePictures: 7,001,570, postPictures: 12,804,415 }

picklechips commented 5 years ago

What happens to the picture if it's not a square? Eg. If I upload a 1920x1080 image, and it gets resized to 600x600 does it get cropped or squished?

picklechips commented 5 years ago

Also, how would you feel about trying to write some tests for the addImage and updateProfilePicture methods?

Would be nice to get in the habit of writing tests for all the code we write, but it's up to you

scholvat commented 5 years ago

I’ll look into writing tests, though I won’t have much time between now and start of term. If an image isn’t square, it gets cropped anchored at the center. Since only the centre will be displayed anyways, this should be fine.

On Tue, Apr 30, 2019 at 12:34 PM Ryan Martin notifications@github.com wrote:

Also, how would you feel about trying to write some tests for the addImage and updateProfilePicture methods?

Would be nice to get in the habit of writing tests for all the code we write, but it's up to you

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/CGUC/skybunk-server/pull/86#issuecomment-488023225, or mute the thread https://github.com/notifications/unsubscribe-auth/ACNK45QEJRPIKACMQY3YH73PTBYIZANCNFSM4HJEHT2A .

picklechips commented 5 years ago

What do you mean since only the center gets displayed anyways?

I'm not sure I like the idea of forcing 600x600 images, which seems to be a downgrade of what we allow right now. It might be worth having a UX discussion before forcing this limitation