Implemented Force image resize

digitalpoint

Well-known member
It would be nice if we could force all uploaded images to be "resized" as an option even if they are within the normal size constraints. Basically allow the image libraries to reduce the file sizes on uploaded images even if they are within the allowed pixel dimensions. As a test, I added $resizeRequired = true; to the XF\Http\Upload class and uploaded the same image with and without the force "resize". The end result was two images that I couldn't visually tell the difference between, with the same dimensions, but the file size was about 5x smaller.

1586455333302.webp

Both images stayed at 1500 x 1500 (and like I already said, I couldn't tell the difference visually). Obviously it wouldn't be ideal for every site (like photography sites that have lossless images being uploaded), but for me (and I suspect a lot of others), an option that yields 5x less space used for image uploads would be a welcome (and simple) addition.
 
Upvote 22
This suggestion has been implemented. Votes are no longer accepted.
This is something I need to implement. Where does that line get added? Are there any other prerequisites for this to work?

Thanks.
 
It wouldn't be terribly hard to do as an addon, although it would be a little ugly because you couldn't do it with a simple extension of the XF\Http\Upload::transformImage() method.

You would need to overwrite the method completely since there's not a good way to hook into the method to just change the one variable that needs to be changed.

You would overwrite the whole method, changing this:

PHP:
$resizeRequired = (
            ($maxWidth && $this->imageWidth > $maxWidth)
            || ($maxHeight && $this->imageHeight > $maxHeight)
        );

to this:

PHP:
$resizeRequired = true;
 
That would be fantastic. Folks have smartphones now with 4k pictures that are huge. Downsizing them to a reasonable size, instead of just refusing them, would be an amazing feature that would also reduce server space.
 
yes hopefully, i think the last time i checked things seemed to get actual bloated somehow during resize...never understood that, but ive been hoping for a better effective solution that didnt need to be implemented custom and direct to server...makes sense that during a webp conversion that part will be better effective...hopefully that sort of just handles that?
 
Back
Top Bottom