qpixel icon indicating copy to clipboard operation
qpixel copied to clipboard

Resize images

Open Taeir opened this issue 3 years ago • 2 comments

Images were not being resized, even when displayed as tiny 40x40 squares. For codidact, the image size limit is 2 MB which somewhat alleviates this problem, but for our self hosted instance we upped max image size to 10 MB for posts (which also affects avatars). As a result, if someone uploads a 6 MB avatar, any page which displays it loads the 6 MB giant avatar and then the browser has to scale it down to display it as a tiny image. This causes huge load times and server traffic for pages like the users overview.

In this PR, images are resized by ActiveStorage to the size matching the requested size (without altering aspect ratio). These resized images are created once when requested and are then cached on the storage provider (in your case, Amazon AWS) and not resized again.

As a bonus, images are also upscaled to the requested size if they are smaller, which should resolve #462 and ensure equal image size for all users.

Finally, the profile page would not maintain aspect ratio of the image (in contrast to all other locations which display the avatar). This is fixed in 879040d.

Fixes #462

Taeir avatar Sep 03 '22 08:09 Taeir

I just noticed that this does no longer go through the upload_remote_url endpoint, which does some transformation on the s3 bucket. The main question is if this method is necessary at all.

Taeir avatar Sep 03 '22 08:09 Taeir

Looks good to merge once #854 is in.

ArtOfCode- avatar Sep 07 '22 15:09 ArtOfCode-

Looks good to merge once #854 is in.

#854 has been merged; are we waiting on anything else or is this ready? (I see this is still a draft)

MoshiKoi avatar Dec 26 '22 01:12 MoshiKoi

Looks good to merge once #854 is in.

#854 has been merged; are we waiting on anything else or is this ready? (I see this is still a draft)

@MoshiKoi This alters the permanent redirect behavior to s3 that is currently present (4c05959c). If we want to keep that the variant would need to be created up front and sent to s3.

Taeir avatar Jan 03 '23 21:01 Taeir

The permanent redirects were put into place because the image requests were disproportionately slow. Investigate the timings to see if this is still the case. Another avenue is to ensure that users still get a 301 on the image request by changing the logic a bit.

Taeir avatar Jul 21 '23 15:07 Taeir