From 5370cf99164ed534f53fa2f3c12e9e7b4876903b Mon Sep 17 00:00:00 2001 From: Marco Antonio Villegas Vega Date: Sun, 16 Jan 2011 22:44:31 -0500 Subject: [PATCH] Fixed Improve the user image resize algorythm - Fixes CT#1414 This also add some minor changes about css on images. --- main/inc/lib/social.lib.php | 4 +-- main/inc/lib/sortabletable.class.php | 2 +- main/inc/lib/usermanager.lib.php | 53 +++++++++++++++------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 4761d1238a..0a858cdeac 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -815,11 +815,11 @@ class SocialManager extends UserManager { } $image_array = UserManager::get_user_picture_path_by_id($uid, 'system', false, true); - $friends_profile = SocialManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_ORIGINAL ); + $friends_profile = UserManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_MEDIUM ); // reduce image $name = api_get_person_name($user_info['firstName'], $user_info['lastName']); - $table_row[] = ''; + $table_row[] = ''; $table_row[] = ''.api_get_person_name(cut($user_info['firstName'],15), cut($user_info['lastName'],15)).''; /* if (api_get_setting('show_email_addresses') == 'true') { diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index 3e90f9ba55..135bbebc51 100755 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -303,7 +303,7 @@ class SortableTable extends HTML_Table { .sub-header { width:100%; padding-top: 10px; padding-right: 10px; padding-left: 10px; height:30px;} .grid_container { width:100%;} .grid_item { height: 120px; width:98px; border:1px dotted #ccc; float:left; padding:5px; margin:8px;} - .grid_element_0 { width:100px; float:left; text-align:center; margin-bottom:5px;} + .grid_element_0 { width:100px; height: 100px; float:left; text-align:center; margin-bottom:5px;} .grid_element_1 { width:100px; float:left; text-align:center;margin-bottom:5px;} .grid_element_2 { width:150px; float:left;} diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 3f05919261..4fe65dee58 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -2258,30 +2258,35 @@ class UserManager } /** - * Resize a picture - * - * @param string file picture - * @param int size in pixels - * @return obj image object - */ - public static function resize_picture($file, $max_size_for_picture) { - if (!class_exists('image')) { - require_once api_get_path(LIBRARY_PATH).'image.lib.php'; - } - $temp = new image($file); - $picture_infos = api_getimagesize($file); - if ($picture_infos[0] > $max_size_for_picture) { - $thumbwidth = $max_size_for_picture; - if (empty($thumbwidth) or $thumbwidth == 0) { - $thumbwidth = $max_size_for_picture; - } - $new_height = round(($thumbwidth / $picture_infos[0]) * $picture_infos[1]); - if ($new_height > $max_size_for_picture) - $new_height = $thumbwidth; - $temp->resize($thumbwidth, $new_height, 0); - } - return $temp; - } + * Resize a picture + * + * @param string file picture + * @param int size in pixels + * @return obj image object + */ + public static function resize_picture($file, $max_size_for_picture) { + if (!class_exists('image')) { + require_once api_get_path(LIBRARY_PATH).'image.lib.php'; + } + $temp = new image($file); + $picture_infos = api_getimagesize($file); + list($width, $height) = api_getimagesize($file); + if ($width >= $height) { + if ($width >= $max_size_for_picture) { + // scale height + $new_height = round($height * ($max_size_for_picture / $width)); + $temp->resize($max_size_for_picture, $new_height, 0); + } + } + else { // height > $width + if ($height >= $max_size_for_picture) { + // scale width + $new_width = round($width * ($max_size_for_picture / $height)); + $temp->resize($new_width, $max_size_for_picture, 0); + } + } + return $temp; + } /** * Gets the current user image