Fixed Newly uploaded avatars saved twice to file system

digitalpoint

Well-known member
Affected version
2.2.8p1
I noticed avatars were sometimes being saved twice when uploading (annoying when you are using a 3rd party API for storing them). It's saved once when you upload it, and then again when you hit "Okay" on the Avatar window.

Did a little digging, and it appears to think there's an avatar crop adjustment even when there is none. If you upload the attached avatar, the xf_user_profile.avatar_crop_y column is set to 16. When you hit "Okay" to close the dialog, that value changes to 15, causing the avatar to be recreated and resaved.

Have tried it with other images, and the same thing happens... with wider images it's varying by 1px on the x axis. In both cases, it causes an extra avatar write because it thinks the crop position changed when it has not.

My guess is that it's a rounding issue (maybe the JavaScript size is calculating the crop pixels differently than the PHP side?). Either way the end result is avatars are being saved twice without being cropped.
 

Attachments

  • SatyrsArriving.jpeg
    SatyrsArriving.jpeg
    101.8 KB · Views: 9

digitalpoint

Well-known member
It does appear to be a rounding issue with the jquery-cropbox plugin that XenForo uses.

In XF\Pub\Controller\Account, changing this:
PHP:
$cropX = $this->filter('avatar_crop_x', 'uint');
$cropY = $this->filter('avatar_crop_y', 'uint');

to this:
PHP:
$cropX = round($this->filter('avatar_crop_x', 'unum'));
$cropY = round($this->filter('avatar_crop_y', 'unum'));

...seems to work around jquery-cropbox sending non-integers and prevent the backend double save/resizing (it is sending a decimal number, not an integer).
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.9).

Change log:
Don't re-save avatars if the crop positioning hasn't changed
There may be a delay before changes are rolled out to the XenForo Community.
 
Top