diff options
author | Henry Sudhof <kellanved@phpbb.com> | 2007-04-25 13:14:11 +0000 |
---|---|---|
committer | Henry Sudhof <kellanved@phpbb.com> | 2007-04-25 13:14:11 +0000 |
commit | c3c5da879ea87db67b9f9aeca4095e371ab55752 (patch) | |
tree | f79fb59b59bb5cf49e5e75b29437bda12c61f41d | |
parent | 8a5452d4ebaf2eb9e02612192b49515897a32c00 (diff) | |
download | forums-c3c5da879ea87db67b9f9aeca4095e371ab55752.tar forums-c3c5da879ea87db67b9f9aeca4095e371ab55752.tar.gz forums-c3c5da879ea87db67b9f9aeca4095e371ab55752.tar.bz2 forums-c3c5da879ea87db67b9f9aeca4095e371ab55752.tar.xz forums-c3c5da879ea87db67b9f9aeca4095e371ab55752.zip |
This should ensure that most avatars are displayed with correct dimensions. Might slow down conversions and there can be no absolute guarantee.
#10105
git-svn-id: file:///svn/phpbb/trunk@7399 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/includes/functions_convert.php | 31 | ||||
-rw-r--r-- | phpBB/install/convertors/convert_phpbb20.php | 4 | ||||
-rw-r--r-- | phpBB/install/convertors/functions_phpbb20.php | 23 |
3 files changed, 48 insertions, 10 deletions
diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index 6da8aedf66..841a6625ee 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -911,17 +911,32 @@ function get_remote_avatar_dim($src,$axis) { return $avatar_cache[$src][$axis]; } - - $avatar_cache[$src] = getimagesize($src); - + + $timeout = ini_get('default_socket_timeout'); + ini_set('default_socket_timeout', 5); + $avatar_cache[$src] = @getimagesize($src); + + $default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X; + $default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y; + $default = array($default_x, $default_y); + if (empty($avatar_cache[$src]) || empty($avatar_cache[$src][0]) || empty($avatar_cache[$src][1])) { - $default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X; - $default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y; - - $avatar_cache[$src] = array($default_x, $default_y); + $avatar_cache[$src] = $default; } - + else + { + // We trust gallery and uploaded avatars to conform to the size settings; we might have to adjust here + if ($avatar_cache[$src][0] > $default_x || $avatar_cache[$src][1] > $default_y) + { + $bigger = ($avatar_cache[$src][0] > $avatar_cache[$src][1]) ? 0 : 1; + $ratio = $default[$bigger] / $avatar_cache[$src][$bigger]; + $avatar_cache[$src][0] = (int)($avatar_cache[$src][0] * $ratio); + $avatar_cache[$src][1] = (int)($avatar_cache[$src][1] * $ratio); + } + } + + ini_set('default_socket_timeout', $timeout); return $avatar_cache[$src][$axis]; } diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index 52f0178b55..c9e9239068 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -866,8 +866,8 @@ if (!$get_info) array('user_avatar', 'users.user_avatar', 'phpbb_import_avatar'), array('user_avatar_type', 'users.user_avatar_type', 'phpbb_avatar_type'), - array('user_avatar_width', 'users.user_avatar', 'get_avatar_width'), - array('user_avatar_height', 'users.user_avatar', 'get_avatar_height'), + array('user_avatar_width', 'users.user_avatar', 'phpbb_get_avatar_width'), + array('user_avatar_height', 'users.user_avatar', 'phpbb_get_avatar_height'), array('user_new_privmsg', 'users.user_new_privmsg', ''), array('user_unread_privmsg', 0, ''), //'users.user_unread_privmsg' diff --git a/phpBB/install/convertors/functions_phpbb20.php b/phpBB/install/convertors/functions_phpbb20.php index 5c3deab0fc..675a64eecb 100644 --- a/phpBB/install/convertors/functions_phpbb20.php +++ b/phpBB/install/convertors/functions_phpbb20.php @@ -1435,6 +1435,29 @@ function phpbb_import_avatar($user_avatar) return ''; } + +/** +* Find out about the avatar's dimensions +*/ +function phpbb_get_avatar_height($user_avatar) +{ + global $convert_row; + + return get_avatar_height($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']); +} + + +/** +* Find out about the avatar's dimensions +*/ +function phpbb_get_avatar_width($user_avatar) +{ + global $convert_row; + + return get_avatar_width($user_avatar, 'phpbb_avatar_type', $convert_row['user_avatar_type']); +} + + /** * Calculate the correct to_address field for private messages */ |