1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Resolved Bug Reports' started by Pepelac, Apr 6, 2012.

  1. Pepelac

    Pepelac Well-Known Member


    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:

    if ($maxFileSize != -&& 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:
    Darkimmortal, Floren, mrGTB and 3 others like this.
  2. Mike

    Mike XenForo Developer Staff Member

    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).

Share This Page