Kellanved wrote:phpBB3 requires the avatar's dimensions to render cleanly, thus people complained about distorted avatars post-conversion.
here's an idea:
while converting, leave dimension -1/-1.
in functions_convert.php, change remote_avatar_dims() to work on one user only, and in addition to database updating, also return list($width, height), such:
Code: Select all
function remote_avatar_dims($user_id, $avatar)
{
global $db;
$width = (int) get_remote_avatar_dim($avatar, 0);
$height = (int) get_remote_avatar_dim($avatar, 1);
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_avatar_width = ' . (int) $width . ', user_avatar_height = ' . (int) $height . '
WHERE user_id = ' . $user_id;
$db->sql_query($sql);
return array($width, $height);
}
}
then, in functions_display.php, change get_user_avatar() so:
Code: Select all
/**
* Get user avatar
*
* @param string $avatar Users assigned avatar name
* @param int $avatar_type Type of avatar
* @param string $avatar_width Width of users avatar
* @param string $avatar_height Height of users avatar
* @param string $alt Optional language string for alt tag within image, can be a language key or text
*
* @return string Avatar image
*/
function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $user_id, $alt = 'USER_AVATAR')
{
global $user, $config, $phpbb_root_path, $phpEx;
if (empty($avatar) || !$avatar_type)
{
return '';
}
$avatar_img = '';
switch ($avatar_type)
{
case AVATAR_UPLOAD:
$avatar_img = $phpbb_root_path . "download.$phpEx?avatar=";
break;
case AVATAR_GALLERY:
$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
break;
case AVATAR_REMOTE:
if ($avatr_width == -1 || $avatar_height == -1)
{
if (!function_exists('remote_avatar_dims'))
{
// the details are left as an exercise to the reader
}
list($avatar_width, $avatar_height) = remote_avatar_dims($user_id, $avatar);
// this call has a side-effect of updating user_avatar_width and user_avatar_height in the db.
}
break;
}
$avatar_img .= $avatar;
return '<img src="' . $avatar_img . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
}
this is just an illustration. you would also have to modify all the places where get_user_avatar() is called to add the $user_id parameter.
the nice thing is that you move the dimension-finding stage from the conversion to the point where each avatar is first used.