Can't fix Avatar uploading - file size is too large

Pepelac

Well-known member
Hi.

After receiving some reports from users, that they can't upload avatars because of error "Your avatar's file size is too large. Please upload an avatar no bigger than XX KB", I've tried to dig into the code.

It's a very strange idea to check user group avatar limits after uploading and resizing the source image. I'm talking about XenForo_Model_Avatar::applyAvatar() method. There is a condition at the line #146:

PHP:
if ($maxFileSize != -1 && filesize($outputFiles[$sizeCode]) > $maxFileSize)

This piece of code checks size of the resampled image. And there is the problem - size of the resampled image can be larger, than the size of the uploaded image.

Here is an example. Let's say, that I have a PNG image about 6 KB. And avatar size limited to 9.8 KB. After uploading, the size of the resampled image is 34 KB. And now user sees the error message and the only thought that we can read in his eyes is "WTF!!! I've just uploaded the image of size 6 KB! :eek: "...

And here are variables from the debug process:
Avatar.webp
 
This is actually one of the big reasons why we resized to JPG in all situations initially, but that created a bunch of complaints. But I don't think we can really do anything about this - it would equally be nonsensical to allow that avatar through given that it became 35KB (not the user's fault, but from the admin's perspective, it's too big).
 
Top Bottom