Is there a way to reduce image file size on upload?

PumpinIron

Well-known member
Licensed customer
In this modern day we live in where images are getting bigger and bigger, I was wondering if such an option (or add-on?) exists where an image size is reduced on upload?

I've got my max image upload size set at 12 MB. That's quite big by all means, however, people are constantly trying to upload photos from their phone that are often times 20 MB or more. They are of course met with file size error messages.

Is there a way to resize an image on upload so that members don't encounter these errors?
 
Also you may need to change your maximum file size.
 
Last edited:
@AndyB helped me set this up. In Options - Attachments, I have max file size 12,000 kb, maximum attachment image dimensions 800 x 600, but there was also something set up in public_html to remove the file size restriction - you'd better ask him about that as I can't remember. My site is very image heavy and never had an issue (even before converting to image optimisation and webp).
 
I'm a bit late to the party but can anybody explain to me exactly how this works? I'm trying to get my head around it.

You can set a maximum attachment size both in pixel dimensions (I have mine set to 2560 h and w) and KB (mine is set to 6144KB).

As I understand it, enabling "optimise images" does 2 things:
  1. Allows resizing on the client size before upload
  2. Converts all image uploads to .webp format
I'm wondering how these 2 factors interact. Is this interpretation correct?
  1. If I upload an image that exceeds the KB limit that will just fail immediately
  2. If the image is a valid KB size, then it will resize the image to fit the pixel dimensions limit
I'm also curious about how the client resizing works. Is it JS based? Does it ever fail? Might some users have it disabled? Is there a server side fallback if so? Stuff like that.

I haven't been able to find any documentation on this beyond this post by @Chris D. If there is any, would you be able to point me in the right direction?

It's a really really nice feature to have auto resizing. And one I wish were enabled on more forums that I use. Image size errors are so annoying and it just screws the experience up compared to SM platforms who seem to handle it without any issues.

Cheers
 
  1. If I upload an image that exceeds the KB limit that will just fail immediately
  2. If the image is a valid KB size, then it will resize the image to fit the pixel dimensions limit
This is correct.

Is it JS based?
Yes
Does it ever fail?
Probably only in the same ways a server side resize might
Might some users have it disabled?
Not really. Edge case would be a very old browser (or having JS disabled, very rare) but that's not really something we need to worry about. That user will hit bigger problems before they even get to uploading images.
Is there a server side fallback if so?
The server would attempt to resize to the max dimensions if the client doesn't do it for some reason.
 
If I upload an image that exceeds the KB limit that will just fail immediately

i am guessing this is not entirely true. does not matter how big the original image is, if it is smaller than configured size after browser side conversion, it does get uploaded just fine?
 
Actually, this is correct. The upload is attempted, even if it exceeds that file size. It will only be rejected if it's too big after a resize is attempted.
 
Is there any general estimation on the reduction achieved by the optimization?

For example - if someone uploads a 10MB picture, what is the size after optimization typically?
How about 20 mb?
etc...
 
there is no easy answer to that. i have seen images with too many colors (like movie posters with gradients) not get compressed much on webp. jpeg works better on them. this is why some of us are waiting for jxl or even avif to become part of xenforo (and the general web). less complex images do compress very well on webp. you might even find images get bigger if you try to upload a highly compressed jpeg in certain cases iirc.

you can logically just upload a bunch of images using the attach files button here and see the compression in real time on variety of images!
 
there is no easy answer to that. i have seen images with too many colors (like movie posters with gradients) not get compressed much on webp. jpeg works better on them. this is why some of us are waiting for jxl or even avif to become part of xenforo (and the general web). less complex images do compress very well on webp. you might even find images get bigger if you try to upload a highly compressed jpeg in certain cases iirc.

you can logically just upload a bunch of images using the attach files button here and see the compression in real time on variety of images!
This helps. Thanks.

I was wondering if I could advise users (for example):

"Our limit hasn't is still 10 mb and hasn't changed, but we enabled image optimization. Now, you can generally upload a 12 mb photo and be okay thanks to optimization."

(made those #s up, but hopefully it shows why I'm asking)
 
depends upon your userbase i guess. most people i know on my board or in general these days would have no idea how big the files they are uploading are. things are just expected to work on the web. and this change by xenforo basically fixed a lot of issues with uploads users faced earlier.

this is also why webp is so disliked generally (on social media i guess). people download images from the web. they are webps. they might still have the extension jpeg coz of how the website is configured. and then they try to use it in a place where webp is not supported and they get frustrated.
 
Back
Top Bottom