Force image resize


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.


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 21


This is something I need to implement. Where does that line get added? Are there any other prerequisites for this to work?



Well-known member
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:

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

to this:

$resizeRequired = true;


Well-known member
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.