diff --git a/main/admin/group_add.php b/main/admin/group_add.php index 9bac236e8f..0338fe67c0 100755 --- a/main/admin/group_add.php +++ b/main/admin/group_add.php @@ -1,9 +1,7 @@ 300) { //limit display width to 300px +if ($image_size['width'] > 300) { //limit display width to 300px $img_attributes .= 'width="300" '; } // get the path,width and height from original picture $big_image = $image_dir.'big_'.$image; $big_image_size = api_getimagesize($big_image); -$big_image_width = $big_image_size[0]; -$big_image_height = $big_image_size[1]; +$big_image_width = $big_image_size['width']; +$big_image_height = $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); if ($image == '') { diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index 346841a9d5..a4c5f960f5 100755 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -885,7 +885,7 @@ function add_edit_template() { $values = $form->exportValues(); // Upload the file. if (!empty($_FILES['template_image']['name'])) { - include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; + require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; $upload_ok = process_uploaded_file($_FILES['template_image']); if ($upload_ok) { @@ -901,33 +901,20 @@ function add_edit_template() { } // Resize the preview image to max default and upload. - require_once api_get_path(LIBRARY_PATH).'image.lib.php'; - $temp = new image($_FILES['template_image']['tmp_name']); - $picture_infos = @getimagesize($_FILES['template_image']['tmp_name']); + $temp = new Image($_FILES['template_image']['tmp_name']); + $picture_info = $temp->get_image_info(); $max_width_for_picture = 100; - if ($picture_infos[0] > $max_width_for_picture) { + if ($picture_info['width'] > $max_width_for_picture) { $thumbwidth = $max_width_for_picture; if (empty($thumbwidth) || $thumbwidth == 0) { $thumbwidth = $max_width_for_picture; } - $new_height = round(($thumbwidth / $picture_infos[0]) * $picture_infos[1]); - + $new_height = round(($thumbwidth / $picture_info['width']) * $picture_info['height']); $temp->resize($thumbwidth, $new_height, 0); - } - - $type = $picture_infos[2]; - - //switch (!empty($type)) { // Obviously wrong line. - switch (type) { - case 2: $temp->send_image('JPG', $upload_dir.$new_file_name); - break; - case 3: $temp->send_image('PNG', $upload_dir.$new_file_name); - break; - case 1: $temp->send_image('GIF', $upload_dir.$new_file_name); - break; - } + } + $temp->send_image($upload_dir.$new_file_name); } } diff --git a/main/admin/user_add.php b/main/admin/user_add.php index cf80da7d6d..91922461e7 100755 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -15,7 +15,6 @@ require_once $libpath.'fileManage.lib.php'; require_once $libpath.'fileUpload.lib.php'; require_once $libpath.'usermanager.lib.php'; require_once $libpath.'formvalidator/FormValidator.class.php'; -require_once $libpath.'image.lib.php'; require_once $libpath.'mail.lib.inc.php'; // Section for the tabs diff --git a/main/admin/user_edit.php b/main/admin/user_edit.php index 97b66d9c03..131f7b44e8 100755 --- a/main/admin/user_edit.php +++ b/main/admin/user_edit.php @@ -60,7 +60,6 @@ require_once $libpath.'fileManage.lib.php'; require_once $libpath.'fileUpload.lib.php'; require_once $libpath.'usermanager.lib.php'; require_once $libpath.'formvalidator/FormValidator.class.php'; -require_once $libpath.'image.lib.php'; require_once $libpath.'mail.lib.inc.php'; $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : intval($_POST['user_id']); @@ -447,15 +446,15 @@ $img_attributes = 'src="'.$image_file.'?rand='.time().'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" '; -if ($image_size[0] > 300) { //limit display width to 300px +if ($image_size['width'] > 300) { //limit display width to 300px $img_attributes .= 'width="300" '; } // get the path,width and height from original picture $big_image = $image_dir.'big_'.$image; $big_image_size = api_getimagesize($big_image); -$big_image_width = $big_image_size[0]; -$big_image_height = $big_image_size[1]; +$big_image_width = $big_image_size['width']; +$big_image_height = $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); if ($image == '') { diff --git a/main/auth/profile.php b/main/auth/profile.php index 3e4389c7e1..f65b16fcc4 100644 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -104,7 +104,6 @@ require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; */ require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; -require_once api_get_path(LIBRARY_PATH).'image.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'social.lib.php'; @@ -546,12 +545,12 @@ function check_user_email($email){ } /* MAIN CODE */ -$filtered_extension = false; -$update_success = false; -$upload_picture_success = false; -$upload_production_success = false; -$msg_fail_changue_email = false; -$msg_is_not_password = false; +$filtered_extension = false; +$update_success = false; +$upload_picture_success = false; +$upload_production_success = false; +$msg_fail_changue_email = false; +$msg_is_not_password = false; if (!empty($_SESSION['change_email'])) { $msg_fail_changue_email= ($_SESSION['change_email'] == 'success'); @@ -601,7 +600,7 @@ if ($form->validate()) { $_SESSION['change_email'] = 'success'; } - // upload picture if a new one is provided + // Upload picture if a new one is provided if ($_FILES['picture']['size']) { if ($new_picture = UserManager::update_user_picture(api_get_user_id(), $_FILES['picture']['name'], $_FILES['picture']['tmp_name'])) { $user_data['picture_uri'] = $new_picture; @@ -800,7 +799,7 @@ if (!empty($msg_is_not_password)){ $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true); $image_syspath['dir'].$image_syspath['file']; -$image_size = @getimagesize($image_syspath['dir'].$image_syspath['file']); +$image_size = api_getimagesize($image_syspath['dir'].$image_syspath['file']); //Web path $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true); @@ -810,7 +809,7 @@ $image_file = $image_dir.$image; $img_attributes = 'src="'.$image_file.'?rand='.time().'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" '; -if ($image_size[0] > 300) { +if ($image_size['width'] > 300) { //limit display width to 300px $img_attributes .= 'width="300" '; } @@ -818,10 +817,10 @@ if ($image_size[0] > 300) { // get the path,width and height from original picture $big_image = $image_dir.'big_'.$image; -$big_image_size = api_getimagesize($big_image); -$big_image_width = $big_image_size[0]; -$big_image_height = $big_image_size[1]; -$url_big_image = $big_image.'?rnd='.time(); +$big_image_size = api_getimagesize($big_image); +$big_image_width = $big_image_size['width']; +$big_image_height = $big_image_size['height']; +$url_big_image = $big_image.'?rnd='.time(); if (api_get_setting('allow_social_tool') == 'true') { echo '
'; @@ -829,9 +828,10 @@ if (api_get_setting('allow_social_tool') == 'true') { SocialManager::show_social_menu('home', null, $user_id, $show_full_profile); echo '
'; - echo '
'; - + echo '
'; echo '
'; + //Useless link + /* echo '
'; if (api_get_setting('extended_profile') == 'true') { $show = isset($_GET['show']) ? '&show='.Security::remove_XSS($_GET['show']) : ''; @@ -841,8 +841,8 @@ if (api_get_setting('allow_social_tool') == 'true') { echo ''; } } - echo '
'; - $form->display(); + echo '';*/ + $form->display(); echo '
'; echo '
'; } else { diff --git a/main/course_info/infocours.php b/main/course_info/infocours.php index dd2baf6bc1..f261e6535b 100755 --- a/main/course_info/infocours.php +++ b/main/course_info/infocours.php @@ -32,20 +32,21 @@ require_once api_get_path(LIBRARY_PATH).'pdf.lib.php'; /* Constants and variables */ define('MODULE_HELP_NAME', 'Settings'); define('COURSE_CHANGE_PROPERTIES', 'COURSE_CHANGE_PROPERTIES'); + $TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE); $TABLEFACULTY = Database :: get_main_table(TABLE_MAIN_CATEGORY); $TABLECOURSEHOME = Database :: get_course_table(TABLE_TOOL_LIST); $TABLELANGUAGES = Database :: get_main_table(TABLE_MAIN_LANGUAGE); $TABLEBBCONFIG = Database :: get_course_table(TOOL_FORUM_CONFIG_TABLE); $currentCourseID = $_course['sysCode']; -$currentCourseRepository = $_course['path']; +$currentCourseRepository = $_course['path']; $is_allowedToEdit = $is_courseAdmin || $is_platformAdmin; $course_setting_table = Database::get_course_table(TABLE_COURSE_SETTING); $course_code = $_course['sysCode']; $course_access_settings = CourseManager :: get_access_settings($course_code); -/* LOGIC FUNCTIONS */ +//LOGIC FUNCTIONS function is_settings_editable() { return $GLOBALS['course_info_is_editable']; } @@ -60,17 +61,14 @@ $show_delete_watermark_text_message = false; if (api_get_setting('pdf_export_watermark_by_course') == 'true') { if (isset($_GET['delete_watermark'])) { PDF::delete_watermark($course_code); - $show_delete_watermark_text_message = true; - + $show_delete_watermark_text_message = true; } } - - $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY); -$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); -$tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN); -$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); -$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); +$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); +$tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN); +$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); +$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); // Get all course categories $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' OR code = '".Database::escape_string($_course['categoryCode'])."' ORDER BY tree_pos"; @@ -110,7 +108,6 @@ while ($cat = Database::fetch_array($res)) { ksort($categories); } - $linebreak = '
'; // Build the form @@ -120,11 +117,21 @@ $form = new FormValidator('update_course'); $form->addElement('html', '
'.Display::return_icon('top.gif', get_lang('Top')).''.Display::return_icon('settings.png', get_lang('CourseSettings'),'','22').' '.get_lang('CourseSettings').'
'); $image_html = ''; -// display course picture + +// Sending image +if ($form->validate() && is_settings_editable()) { + // update course picture + $picture = $_FILES['picture']; + if (!empty($picture['name'])) { + $picture_uri = CourseManager::update_course_picture($course_code, $picture['name'], $picture['tmp_name']); + } +} + +// Display course picture $course_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository; // course path if (file_exists($course_path.'/course-pic85x85.png')) { $course_web_path = api_get_path(WEB_COURSE_PATH).$currentCourseRepository; // course web path - $course_medium_image = $course_web_path.'/course-pic85x85.png'; // redimensioned image 85x85 + $course_medium_image = $course_web_path.'/course-pic85x85.png?'.rand(1,1000); // redimensioned image 85x85 $image_html = '
'; } $form->addElement('html', $image_html); @@ -165,8 +172,7 @@ if (api_get_setting('pdf_export_watermark_by_course') == 'true') { if ($url != false) { $delete_url = ''.Display::return_icon('delete.png',get_lang('DelImage')).''; $form->addElement('html', '
'); - } - $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); + } $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); } @@ -220,8 +226,6 @@ $form->addElement('radio', 'email_alert_manager_on_new_quiz', null, get_lang('Qu $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"'); - - // USER RIGHTS $form->addElement('html', '
'.Display::return_icon('top.gif', get_lang('Top')).''.Display::return_icon('user.png', get_lang('UserRights'),'','22').' '.get_lang('UserRights').'
'); $form->addElement('radio', 'allow_user_edit_agenda', get_lang('AllowUserEditAgenda'), get_lang('AllowUserEditAgendaActivate'), 1); @@ -246,7 +250,6 @@ $form->addElement('html', '
< $form->addElement('radio', 'allow_open_chat_window', get_lang('AllowOpenchatWindow'), get_lang('AllowOpenChatWindowActivate'), 1); $form->addElement('radio', 'allow_open_chat_window', null, get_lang('AllowOpenChatWindowDeactivate'), 0); - $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"'); // LEARNING PATH @@ -283,7 +286,6 @@ $form->addElement('radio', 'display_info_advance_inside_homecourse', null, get_l $form->addElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'), 3); $form->addElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DoNotDisplayAnyAdvance'), 0); - $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"'); @@ -342,12 +344,12 @@ $form->setDefaults($values); // Validate form if ($form->validate() && is_settings_editable()) { $update_values = $form->exportValues(); - +/* // update course picture $picture = $_FILES['picture']; if (!empty($picture['name'])) { $picture_uri = CourseManager::update_course_picture($course_code, $picture['name'], $picture['tmp_name']); - } + }*/ $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path']; diff --git a/main/course_progress/thematic_controller.php b/main/course_progress/thematic_controller.php index 7ba7578d54..ecfc44ee9f 100755 --- a/main/course_progress/thematic_controller.php +++ b/main/course_progress/thematic_controller.php @@ -121,7 +121,7 @@ class ThematicController $thematic_data[$thematic_id] = $thematic->get_thematic_list($thematic_id); $data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id); } else { - $thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id()); + $thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id()); $data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance(); $data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances(); diff --git a/main/document/document.php b/main/document/document.php index c9f13687a6..f06ee1d5d1 100755 --- a/main/document/document.php +++ b/main/document/document.php @@ -803,32 +803,20 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold $upload_dir = api_get_path(SYS_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/'; // Resize image to max default and end upload - require_once (api_get_path(LIBRARY_PATH).'image.lib.php'); - $temp = new image($_FILES['template_image']['tmp_name']); - $picture_infos = @getimagesize($_FILES['template_image']['tmp_name']); + $temp = new Image($_FILES['template_image']['tmp_name']); + $picture_info = $temp->get_image_info(); $max_width_for_picture = 100; - if ($picture_infos[0] > $max_width_for_picture) { + if ($picture_info['width'] > $max_width_for_picture) { $thumbwidth = $max_width_for_picture; if (empty($thumbwidth) || $thumbwidth == 0) { $thumbwidth = $max_width_for_picture; } - $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]); - + $new_height = round(($thumbwidth/$picture_info['width'])*$picture_info['height']); $temp->resize($thumbwidth, $new_height, 0); } - - $type = $picture_infos[2]; - - switch (!empty($type)) { - case 2 : $temp->send_image('JPG', $upload_dir.$new_file_name); - break; - case 3 : $temp->send_image('PNG', $upload_dir.$new_file_name); - break; - case 1 : $temp->send_image('GIF', $upload_dir.$new_file_name); - break; - } + $temp->send_image($upload_dir.$new_file_name); } } diff --git a/main/document/slideshow.inc.php b/main/document/slideshow.inc.php index 79f0bcc527..d4fcd82904 100755 --- a/main/document/slideshow.inc.php +++ b/main/document/slideshow.inc.php @@ -3,24 +3,10 @@ /** * @author Patrick Cool - * @package ghamilo.document + * @package chamilo.document * @todo convert comments to be understandable to phpDocumentor */ -/* -Developped by Patrick Cool -patrick.cool@UGent.be -Ghent University -Mai 2004 -http://icto.UGent.be - -Please bear in mind that this is only an alpha release. -I wrote this quite quick and didn't think too much about it in advance. -It is not perfect at all but it is workable and usefull (I think) -Do not consider this as a powerpoint replacement, although it has -the same starting point. -*/ - /* Description: This is a plugin for the documents tool. It looks for .jpg, .jpeg, .gif, .png @@ -58,8 +44,8 @@ function resize_image($image, $target_width, $target_height, $slideshow = 0) { $result[] = $new_sizes['width']; } else { $size = api_getimagesize($image); - $result[] = $size[1]; - $result[] = $size[0]; + $result[] = $size['height']; + $result[] = $size['width']; } return $result; } diff --git a/main/exercice/hotspot_admin.inc.php b/main/exercice/hotspot_admin.inc.php index 1a739dc91e..a4349e559d 100755 --- a/main/exercice/hotspot_admin.inc.php +++ b/main/exercice/hotspot_admin.inc.php @@ -550,8 +550,7 @@ if ($modifyAnswers) { get_flat_list(); //loading list of LPs @@ -858,8 +857,7 @@ if ($modifyAnswers) { get_flat_list(); $select_lp_id=array(); diff --git a/main/exercice/question.class.php b/main/exercice/question.class.php index 5a7de074ac..f8a9d9f257 100755 --- a/main/exercice/question.class.php +++ b/main/exercice/question.class.php @@ -360,17 +360,12 @@ abstract class Question // if the question has got an ID if ($this->id) { $extension = pathinfo($PictureName, PATHINFO_EXTENSION); - $this->picture ='quiz-'.$this->id.'.jpg'; - require_once api_get_path(LIBRARY_PATH).'image.lib.php'; - $detected = array('gif','jpeg','jpg','png'); - if (in_array(strtolower($extension), $detected)) { - $o_img = new image($Picture); - $o_img->send_image('JPG',$picturePath.'/'.$this->picture); - $document_id = add_document($this->course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture); - - if ($document_id) { - return api_item_property_update($this->course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id); - } + $this->picture = 'quiz-'.$this->id.'.jpg'; + $o_img = new Image($Picture); + $o_img->send_image($picturePath.'/'.$this->picture, -1, 'jpg'); + $document_id = add_document($this->course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture); + if ($document_id) { + return api_item_property_update($this->course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id); } } @@ -391,36 +386,33 @@ abstract class Question // if the question has an ID if($this->id) { // Get dimensions from current image. - $current_img = imagecreatefromjpeg($picturePath.'/'.$this->picture); + $my_image = new Image($picturePath.'/'.$this->picture); + + $current_image_size = $my_image->get_image_size(); + $current_width = $current_image_size['width']; + $current_height = $current_image_size['height']; - $current_image_size = getimagesize($picturePath.'/'.$this->picture); - $current_height = imagesy($current_img); - $current_width = imagesx($current_img); - - if($current_image_size[0] < $Max && $current_image_size[1] <$Max) + if($current_width < $Max && $current_height <$Max) return true; elseif($current_height == "") return false; // Resize according to height. - if ($Dimension == "height") - { + if ($Dimension == "height") { $resize_scale = $current_height / $Max; $new_height = $Max; $new_width = ceil($current_width / $resize_scale); } // Resize according to width - if ($Dimension == "width") - { + if ($Dimension == "width") { $resize_scale = $current_width / $Max; $new_width = $Max; $new_height = ceil($current_height / $resize_scale); } // Resize according to height or width, both should not be larger than $Max after resizing. - if ($Dimension == "any") - { + if ($Dimension == "any") { if ($current_height > $current_width || $current_height == $current_width) { $resize_scale = $current_height / $Max; @@ -434,28 +426,13 @@ abstract class Question $new_height = ceil($current_height / $resize_scale); } } - - // Create new image - $new_img = imagecreatetruecolor($new_width, $new_height); - $bgColor = imagecolorallocate($new_img, 255,255,255); - imagefill($new_img , 0,0 , $bgColor); - - // Resize image - imagecopyresized($new_img, $current_img, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height); - - // Write image to file - $result = imagejpeg($new_img, $picturePath.'/'.$this->picture, 100); - - // Delete temperory images, clear memory - imagedestroy($current_img); - imagedestroy($new_img); - - if ($result) - { + + $my_image->resize($new_width, $new_height); + $result = $my_image->send_image($picturePath.'/'.$this->picture); + + if ($result) { return true; - } - else - { + } else { return false; } } diff --git a/main/exercice/question_admin.inc.php b/main/exercice/question_admin.inc.php index c4846870ba..e4c67454c8 100755 --- a/main/exercice/question_admin.inc.php +++ b/main/exercice/question_admin.inc.php @@ -12,7 +12,6 @@ /* INIT SECTION */ require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; -require_once api_get_path(LIBRARY_PATH).'image.lib.php'; // ALLOWED_TO_INCLUDE is defined in admin.php if(!defined('ALLOWED_TO_INCLUDE')) { diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 55559ed15a..a3c98f3eef 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -306,7 +306,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id) { $img_attributes = ''; if (!empty($image_size)) { - if ($image_size[0] > 100 || $image_size[1] > 100) { + if ($image_size['width'] > 100 || $image_size['height'] > 100) { //limit display width and height to 100px $img_attributes = 'width="100" height="100"'; } diff --git a/main/forum/index.php b/main/forum/index.php index e2999972ff..b10ba5f06d 100755 --- a/main/forum/index.php +++ b/main/forum/index.php @@ -332,7 +332,7 @@ if (is_array($forum_categories_list)) { $img_attributes = ''; if (!empty($image_size)) { - if ($image_size[0] > 100 || $image_size[1] > 100) { + if ($image_size['width'] > 100 || $image_size['height'] > 100) { //limit display width and height to 100px $img_attributes = 'width="100" height="100"'; } diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 3ed51d8b04..0279e5c11e 100755 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -95,6 +95,7 @@ ini_set('auto_detect_line_endings', '1'); require_once $lib_path.'database.lib.php'; require_once $lib_path.'display.lib.php'; require_once $lib_path.'text.lib.php'; +require_once $lib_path.'image.lib.php'; require_once $lib_path.'array.lib.php'; require_once $lib_path.'security.lib.php'; require_once $lib_path.'events.lib.inc.php'; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index e4bf210720..73da2bdf69 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2486,57 +2486,29 @@ class CourseManager { */ public static function update_course_picture($course_code, $filename, $source_file = null) { - $course_info = api_get_course_info($course_code); - $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path - $course_image = $store_path.'/course-pic.png'; // image name for courses - $course_medium_image = $store_path.'/course-pic85x85.png'; - $extension = strtolower(substr(strrchr($filename, '.'), 1)); - - $result = false; - $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); - if (in_array($extension, $allowed_picture_types)) { - if (file_exists($course_image)) { - @unlink($course_image); - } - if (file_exists($course_medium_image)) { - @unlink($course_medium_image); - } - if ($extension != 'png') { - // convert image to png extension - if ($extension == 'jpg' || $extension == 'jpeg') { - $image = imagecreatefromjpeg($source_file); - } else { - $image = imagecreatefromgif($source_file); - } - ob_start(); - imagepng($image); - $imagevariable = ob_get_contents(); - ob_end_clean(); - // save picture - if (@file_put_contents($course_image, $imagevariable)) { - $result = true; - } - } else { - $result = @move_uploaded_file($source_file, $course_image); - } - } + $course_info = api_get_course_info($course_code); + $store_path = api_get_path(SYS_COURSE_PATH).$course_info['path']; // course path + $course_image = $store_path.'/course-pic.png'; // image name for courses + $course_medium_image = $store_path.'/course-pic85x85.png'; + $extension = strtolower(substr(strrchr($filename, '.'), 1)); - // redimension image to 85x85 - if ($result) { - $max_size_for_picture = 85; - if (!class_exists('image')) { - require_once api_get_path(LIBRARY_PATH).'image.lib.php'; - } - $medium = new image($course_image); - $picture_infos = api_getimagesize($course_image); - if ($picture_infos[0] > $max_size_for_picture) { - $width = 100000; - $height = $max_size_for_picture; - $medium->resize($width, $height, 0); - } - $rs = $medium->send_image('PNG', $store_path.'/course-pic85x85.png'); + $result = false; + if (file_exists($course_image)) { + @unlink($course_image); + } + if (file_exists($course_medium_image)) { + @unlink($course_medium_image); } + $my_course_image = new Image($source_file); + $result = $my_course_image->send_image($course_image, -1, 'png'); + //Redimension image to 100x85 + if ($result) { + $medium = new Image($course_image); + $picture_infos = $medium->get_image_size(); + $medium->resize(100, 85, 0, false); + $rs = $medium->send_image($store_path.'/course-pic85x85.png', -1, 'png'); + } return $result; } diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php index 135bb833b9..c5d39fd336 100755 --- a/main/inc/lib/group_portal_manager.lib.php +++ b/main/inc/lib/group_portal_manager.lib.php @@ -674,23 +674,16 @@ class GroupPortalManager // Storing the new photos in 4 versions with various sizes. - $picture_info = @getimagesize($source_file); - $type = $picture_info[2]; - - $small = self::resize_picture($source_file, 22); + $small = self::resize_picture($source_file, 22); $medium = self::resize_picture($source_file, 85); $normal = self::resize_picture($source_file, 200); - $big = new image($source_file); // This is the original picture. + $big = new Image($source_file); // This is the original picture. $ok = false; - $detected = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); - - if (in_array($type, array_keys($detected))) { - $ok = $small->send_image($detected[$type], $path.'small_'.$filename) - && $medium->send_image($detected[$type], $path.'medium_'.$filename) - && $normal->send_image($detected[$type], $path.'big_'.$filename) - && $big->send_image($detected[$type], $path.$filename); - } + $ok = $small->send_image($path.'small_'.$filename) + && $medium->send_image($path.'medium_'.$filename) + && $normal->send_image($path.'big_'.$filename) + && $big->send_image($path.$filename); return $ok ? $filename : false; } @@ -764,18 +757,15 @@ class GroupPortalManager * @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'; - } + public static function resize_picture($file, $max_size_for_picture) { $temp = new image($file); $picture_infos = api_getimagesize($file); - if ($picture_infos[0] > $max_size_for_picture) { + if ($picture_infos['width'] > $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]); + $new_height = round(($thumbwidth / $picture_infos['width']) * $picture_infos['height']); if ($new_height > $max_size_for_picture) $new_height = $thumbwidth; $temp->resize($thumbwidth, $new_height, 0); @@ -826,9 +816,9 @@ class GroupPortalManager $picture['style'] = ''; if ($height > 0) { $dimension = api_getimagesize($picture['file']); - $margin = (($height - $dimension[1]) / 2); + $margin = (($height - $dimension['width']) / 2); //@ todo the padding-top should not be here - $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension[0].'px; height:'.$dimension[1].';" '; + $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension['width'].'px; height:'.$dimension['height'].';" '; } } else { //$file = api_get_path(SYS_CODE_PATH).$patch_profile.$user_id.'/'.$picture_file; diff --git a/main/inc/lib/image.lib.php b/main/inc/lib/image.lib.php index 59da3dc90c..e2b89f277d 100755 --- a/main/inc/lib/image.lib.php +++ b/main/inc/lib/image.lib.php @@ -1,52 +1,227 @@ + */ - function image($bgfile = '') { - image::addbackground($bgfile); +//@todo move in a DB configuration setting + +define('IMAGE_PROCESSOR', 'gd'); // imagick or gd strings + +class Image { + var $image_wrapper = null; + + function __construct($path) { + $path = preg_match(VALID_WEB_PATH, $path) ? (api_is_internal_path($path) ? api_get_path(TO_SYS, $path) : $path) : $path; + if (IMAGE_PROCESSOR == 'gd') { + $this->image_wrapper = new GDWrapper($path); + } else { + $this->image_wrapper = new ImagickWrapper($path); + } + } + public function resize($thumbw, $thumbh, $border = 0, $specific_size = false) { + $this->image_wrapper->resize($thumbw, $thumbh, $border, $specific_size ); + } + public function send_image($file = '', $compress = -1, $convert_file_to = null) { + return $this->image_wrapper->send_image($file, $compress, $convert_file_to); + } + public function get_image_size() { + return $this->image_wrapper->get_image_size(); } + public function get_image_info() { + return $this->image_wrapper->get_image_info(); + } +} - function createimagefromtype($file, $handler) { - $size = api_getimagesize($file); - $type = $size[2]; +abstract class ImageWrapper { + var $debug = true; + var $path; + var $width; + var $height; + var $type; + var $allowed_extensions = array('jpeg', 'jpg', 'png', 'gif'); + var $image_validated = false; + + public function __construct($path) { + if (empty($path)) { + return false; + } + $this->path = preg_match(VALID_WEB_PATH, $path) ? (api_is_internal_path($path) ? api_get_path(TO_SYS, $path) : $path) : $path; + $this->set_image_wrapper(); //Creates image obj + } + + abstract function set_image_wrapper(); + abstract function fill_image_info(); + abstract function get_image_size(); + abstract function resize($thumbw, $thumbh, $border, $specific_size = false); + abstract function send_image($file = '', $compress = -1, $convert_file_to); + public function get_image_info() { + return array('width' => $this->width, + 'height' => $this->height, + 'type' => $this->type + ); + } +} +/** + * Imagick Chamilo wrapper + * + * @author jmontoya + * + */ +class ImagickWrapper extends ImageWrapper { + var $image; + var $filter = Imagick::FILTER_LANCZOS; + + public function __construct($path) { + parent::__construct($path); + } + public function set_image_wrapper() { + try { + $this->image = new Imagick($this->path); + + if ($this->image) { + $this->fill_image_info(); //Fills height, width and type + } + if ($debug) error_log('set_image_wrapper loaded'); + } catch(ImagickException $e) { + if ($this->debug) error_log($e->getMessage()); + } + } + + public function fill_image_info() { + $image_info = $this->image->identifyImage(); + + $this->width = $image_info['geometry']['width']; + $this->height = $image_info['geometry']['height']; + $this->type = strtolower($this->image->getImageFormat()); + + if (in_array($this->type, $this->allowed_extensions)) { + $this->image_validated = true; + if ($this->debug) error_log('image_validated true'); + } + } + + public function get_image_size() { + if ($this->image_validated) { + return $imagesize = $this->image->getImageGeometry(); + } + } + + //@todo implement border logic case for Imagick + public function resize($thumbw, $thumbh, $border, $specific_size = false) { + if (!$this->image_validated) return false; + + if ($specific_size) { + $width = $thumbw; + $height = $thumbh; + } else { + $scale = ($this->width > 0 && $this->height > 0) ? min($thumbw / $this->width, $thumbh / $this->height) : 0; + $width = (int)($this->width * $scale); + $height = (int)($this->height * $scale); + } + $result = $this->image->resizeImage($width, $height, $this->filter, 1); + $this->width = $thumbw; + $this->height = $thumbh; + } + + public function send_image($file = '', $compress = -1, $convert_file_to) { + if (!$this->image_validated) return false; + $type = $this->type; + if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { + $type = $convert_file_to; + } switch ($type) { - case 2 : $imhandler = @imagecreatefromjpeg($file); break; - case 3 : $imhandler = @imagecreatefrompng($file); break; - case 1 : $imhandler = @imagecreatefromgif($file); break; + case 'jpeg': + case 'jpg': + if (!$file) header("Content-type: image/jpeg"); + break; + case 'png': + if (!$file) header("Content-type: image/png"); + break; + case 'gif': + if (!$file) header("Content-type: image/gif"); + break; } - - $xtmpstr = $handler.'x'; - $ytmpstr = $handler.'y'; - - $this->$xtmpstr = $size[0]; - $this->$ytmpstr = $size[1]; - - return $imhandler; + $result = false; + try { + $result = $this->image->writeImage($file); + } catch(ImagickException $e) { + if ($this->debug) error_log($e->getMessage()); + } + + if (!$file) { + echo $this->image; + $this->image->clear(); + $this->image->destroy(); + } else { + $this->image->clear(); + $this->image->destroy(); + return $result; + } } +} - function resize($thumbw, $thumbh, $border, $specific_size = false) { - - $size [0] = $this->bgx; - $size [1] = $this->bgy; +/** + * php-gd wrapper + * + * + */ +class GDWrapper extends ImageWrapper { + var $bg; + + function __construct($path) { + parent::__construct($path); + } + + public function set_image_wrapper() { + $handler = null; + $this->fill_image_info(); + switch ($this->type) { + case 1 : + $handler = @imagecreatefromgif($this->path); + $this->type = 'gif'; + break; + case 2 : + $handler = @imagecreatefromjpeg($this->path); + $this->type = 'jpg'; + break; + case 3 : + $handler = @imagecreatefrompng($this->path); + $this->type = 'png'; + break; + } + if ($handler) { + $this->image_validated = true; + $this->bg = $handler; + @imagealphablending($this->bg, true); + } + } + + public function get_image_size() { + return $return_array = array('width'=>$this->width,'height'=>$this->height); + } + + public function fill_image_info() { + $image_info = getimagesize($this->path); + $this->width = $image_info[0]; + $this->height = $image_info[1]; + $this->type = $image_info[2]; + } + + public function resize($thumbw, $thumbh, $border, $specific_size = false) { + if (!$this->image_validated) return false; if ($border == 1) { if ($specific_size) { $width = $thumbw; $height = $thumbh; } else { - $scale = min($thumbw / $size[0], $thumbh / $size[1]); - $width = (int)($size[0] * $scale); - $height = (int)($size[1] * $scale); + $scale = min($thumbw / $this->width, $thumbh / $this->height); + $width = (int)($this->width * $scale); + $height = (int)($this->height * $scale); } $deltaw = (int)(($thumbw - $width) / 2); $deltah = (int)(($thumbh - $height) / 2); @@ -54,58 +229,78 @@ class image { if (!empty($this->color)) { @imagefill($dst_img, 0, 0, $this->color); } - $this->bgx = $thumbw; - $this->bgy = $thumbh; + $this->width = $thumbw; + $this->height = $thumbh; } elseif ($border == 0) { if ($specific_size) { $width = $thumbw; $height = $thumbh; } else { - $scale = ($size[0] > 0 && $size[1] > 0) ? min($thumbw / $size[0], $thumbh / $size[1]) : 0; - $width = (int)($size[0] * $scale); - $height = (int)($size[1] * $scale); + $scale = ($this->width > 0 && $this->height > 0) ? min($thumbw / $this->width, $thumbh / $this->height) : 0; + $width = (int)($this->width * $scale); + $height = (int)($this->height * $scale); } $deltaw = 0; $deltah = 0; $dst_img = @ImageCreateTrueColor($width, $height); - $this->bgx = $width; - $this->bgy = $height; + $this->width = $width; + $this->height = $height; } $src_img = $this->bg; @ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img)); - $this->bg=$dst_img; + $this->bg = $dst_img; @imagedestroy($src_img); } - - function addbackground($bgfile) { - if (!empty($bgfile) && file_exists($bgfile)) { - $this->bg = image::createimagefromtype($bgfile, 'bg'); - @imagealphablending($this->bg, true); + + public function send_image($file = '', $compress = -1, $convert_file_to = null) { + if (!$this->image_validated) return false; + $type = $this->type; + if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { + $type = $convert_file_to; + } + switch ($type) { + case 'jpeg': + case 'jpg': + if (!$file) header("Content-type: image/jpeg"); + if ($compress == -1) $compress = 100; + return imagejpeg($this->bg, $file, $compress); + break; + case 'png': + if (!$file) header("Content-type: image/png"); + if ($compress != -1) { + @imagetruecolortopalette($this->bg, true, $compress); + } + return imagepng($this->bg, $file, $compress); + break; + case 'gif': + if (!$file) header("Content-type: image/gif"); + if ($compress != -1) { + @imagetruecolortopalette($this->bg, true, $compress); + } + return imagegif($this->bg, $file, $compress); + break; + default: return 0; } + // TODO: Occupied memory is not released, because the following fragment of code is actually dead. + @imagedestroy($this->bg); + //@imagedestroy($this->logo); } + + + /* + * @deprecated + * function addlogo($file) { $this->logo = image::createimagefromtype($file, 'logo'); @imagealphablending($this->logo , true); $size = api_getimagesize($file); - $this->logox = $size[0]; - $this->logoy = $size[1]; - } + $this->logox = $size['width']; + $this->logoy = $size['height']; + }*/ - function mergelogo($x, $y, $alpha = 100) { - if ($x < 0) $x = $this->bgx - $this->logox + $x; - if ($y < 0) $y = $this->bgy - $this->logoy + $y; - return @imagecopymerge($this->bg, $this->logo, $x, $y, 0, 0, $this->logox, $this->logoy, $alpha); - } - - function makecolor($red, $green, $blue) { - $this->color = @imagecolorallocate($this->bg, $red, $green, $blue); - } - - function setfont($fontfile) { - $this->fontfile = $fontfile; - } + /* @deprecated function addtext ($text, $x = 0, $y = 0, $size = 12, $angle = 0) { putenv('GDFONTPATH=' . realpath('.')); $this->fontfile='verdana'; @@ -113,48 +308,35 @@ class image { $box = @imagettfbbox($size, $angle, $this->fontfile, $text); if ($x < 0) { - $x = $this->bgx - max($box[2], $box[4]) + $x; + $x = $this->width - max($box[2], $box[4]) + $x; } else { $x = max(-$box[0], -$box[6]) + $x; } if ($y < 0) { - $y = $this->bgy - max($box[1], $box[3]) + $y; + $y = $this->height - max($box[1], $box[3]) + $y; } else { $y = max(-$box[7], -$box[5]) + $y; } @imagettftext($this->bg, $size, $angle, $x, $y, $this->color, $this->fontfile , $text); } + */ + + /* //@deprecated + function mergelogo($x, $y, $alpha = 100) { + if ($x < 0) $x = $this->width - $this->logox + $x; + if ($y < 0) $y = $this->height - $this->logoy + $y; + return @imagecopymerge($this->bg, $this->logo, $x, $y, 0, 0, $this->logox, $this->logoy, $alpha); + }*/ - function send_image($type, $file = '', $compress = -1) { - - switch ($type) { - case 'JPG': - if (!$file) header("Content-type: image/jpeg"); - if ($compress == -1) $compress = 100; - return imagejpeg($this->bg, $file, $compress); - - case 'PNG': - if (!$file) header("Content-type: image/png"); - if ($compress != -1) { - @imagetruecolortopalette($this->bg, true, $compress); - } - return imagepng($this->bg, $file, $compress); - - case 'GIF': - if (!$file) header("Content-type: image/gif"); - if ($compress != -1) { - @imagetruecolortopalette($this->bg, true, $compress); - } - return imagegif($this->bg, $file, $compress); - - default: return 0; - } - - // TODO: Occupied memory is not released, because the following fragment of code is actually dead. - @imagedestroy($this->bg); - @imagedestroy($this->logo); - + /* //@deprecated + function makecolor($red, $green, $blue) { + $this->color = @imagecolorallocate($this->bg, $red, $green, $blue); } - -} + */ + /* //@deprecated + function setfont($fontfile) { + $this->fontfile = $fontfile; + }*/ + +} \ No newline at end of file diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 1d95785478..407ca45ba6 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -28,6 +28,8 @@ define('ANONYMOUS', 6); * the teacher through HTMLPurifier */ define('COURSEMANAGERLOWSECURITY', 10); + + // Table of status $_status_list[COURSEMANAGER] = 'teacher'; // 1 $_status_list[SESSIONADMIN] = 'session_admin'; // 3 @@ -4471,7 +4473,8 @@ if (!function_exists('json_encode')) { * @link http://www.dokeos.com/forum/viewtopic.php?t=16355 */ function api_getimagesize($path) { - return @getimagesize(preg_match(VALID_WEB_PATH, $path) ? (api_is_internal_path($path) ? api_get_path(TO_SYS, $path) : $path) : $path); + $image = new Image($path); + return $image->get_image_size(); } /** @@ -4483,10 +4486,8 @@ function api_getimagesize($path) { * @return array Calculated new width and height */ function api_resize_image($image, $target_width, $target_height) { - $image_properties = api_getimagesize($image); - $image_width = $image_properties[0]; - $image_height = $image_properties[1]; - return api_calculate_image_size($image_width, $image_height, $target_width, $target_height); + $image_properties = api_getimagesize($image); + return api_calculate_image_size($image_properties['width'], $image_properties['height'], $target_width, $target_height); } /** diff --git a/main/inc/lib/pdf.lib.php b/main/inc/lib/pdf.lib.php index 3d93e7b63c..39bf1348a3 100644 --- a/main/inc/lib/pdf.lib.php +++ b/main/inc/lib/pdf.lib.php @@ -326,30 +326,12 @@ class PDF { $course_image = $store_path.'/'.api_get_current_access_url_id().'_pdf_watermark.png'; $extension = strtolower(substr(strrchr($filename, '.'), 1)); $result = false; - $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); - if (in_array($extension, $allowed_picture_types)) { - if (file_exists($course_image)) { - @unlink($course_image); - } - if ($extension != 'png') { - // convert image to png extension - if ($extension == 'jpg' || $extension == 'jpeg') { - $image = imagecreatefromjpeg($source_file); - } else { - $image = imagecreatefromgif($source_file); - } - ob_start(); - imagepng($image); - $imagevariable = ob_get_contents(); - ob_end_clean(); - // save picture - if (@file_put_contents($course_image, $imagevariable)) { - $result = true; - } - } else { - $result = move_uploaded_file($source_file, $course_image); - } + + if (file_exists($course_image)) { + @unlink($course_image); } + $my_image = new Image($source_file); + $result = $my_image->send_image($course_image, -1, 'png'); if ($result) { $result = $web_path; } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index d0deb97ea1..eb34544b48 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -878,8 +878,8 @@ class SocialManager extends UserManager { // get the path,width and height from original picture $big_image = $webdir.'big_'.$user_object->picture_uri; $big_image_size = api_getimagesize($big_image); - $big_image_width = $big_image_size[0]; - $big_image_height = $big_image_size[1]; + $big_image_width = $big_image_size['width']; + $big_image_height = $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); echo '
'; } else { diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 76eaab01eb..b1002dd9f4 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -799,17 +799,17 @@ class UserManager /** * Creates new user pfotos in various sizes of a user, or deletes user pfotos. * Note: This method relies on configuration setting from dokeos/main/inc/conf/profile.conf.php - * @param int $user_id The user internal identitfication number. - * @param string $file The common file name for the newly created pfotos. It will be checked and modified for compatibility with the file system. - * If full name is provided, path component is ignored. - * If an empty name is provided, then old user photos are deleted only, @see UserManager::delete_user_picture() as the prefered way for deletion. - * @param string $source_file The full system name of the image from which user photos will be created. - * @return string/bool Returns the resulting common file name of created images which usually should be stored in database. + * @param int $user_id The user internal identitfication number. + * @param string $file The common file name for the newly created pfotos. + * It will be checked and modified for compatibility with the file system. + * If full name is provided, path component is ignored. + * If an empty name is provided, then old user photos are deleted only, + * @see UserManager::delete_user_picture() as the prefered way for deletion. + * @param string $source_file The full system name of the image from which user photos will be created. + * @return string/bool Returns the resulting common file name of created images which usually should be stored in database. * When deletion is recuested returns empty string. In case of internal error or negative validation returns FALSE. */ public static function update_user_picture($user_id, $file = null, $source_file = null) { - - // Validation 1. if (empty($user_id)) { return false; } @@ -878,23 +878,19 @@ class UserManager $filename = $user_id.'_'.$filename; } - // Storing the new photos in 4 versions with various sizes. - $picture_info = api_getimagesize($source_file); - - $type = $picture_info[2]; - $small = self::resize_picture($source_file, 22); - $medium = self::resize_picture($source_file, 85); + // Storing the new photos in 4 versions with various sizes. + + $small = self::resize_picture($source_file, 22); + $medium = self::resize_picture($source_file, 85); $normal = self::resize_picture($source_file, 200); - $big = new image($source_file); // This is the original picture. + + $big = new Image($source_file); // This is the original picture. $ok = false; - $detected = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); - if (in_array($type, array_keys($detected))) { - $ok = $small->send_image($detected[$type], $path.'small_'.$filename) - && $medium->send_image($detected[$type], $path.'medium_'.$filename) - && $normal->send_image($detected[$type], $path.$filename) - && $big->send_image($detected[$type], $path.'big_'.$filename); - } + $ok = $small->send_image($path.'small_'.$filename) && + $medium->send_image($path.'medium_'.$filename) && + $normal->send_image($path.$filename) && + $big->send_image( $path.'big_'.$filename); return $ok ? $filename : false; } @@ -2288,14 +2284,13 @@ class UserManager * @todo move this function somewhere else image.lib? * @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'; - } + public static function resize_picture($file, $max_size_for_picture) { $temp = null; if (file_exists($file)) { - $temp = new image($file); - list($width, $height) = api_getimagesize($file); + $temp = new Image($file); + $image_size = $temp->get_image_size($file); + $width = $image_size['width']; + $height = $image_size['height']; if ($width >= $height) { if ($width >= $max_size_for_picture) { // scale height @@ -2357,9 +2352,9 @@ class UserManager $picture['style'] = ''; if ($height > 0) { $dimension = api_getimagesize($picture['file']); - $margin = (($height - $dimension[1]) / 2); + $margin = (($height - $dimension['width']) / 2); //@ todo the padding-top should not be here - $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension[0].'px; height:'.$dimension[1].'px;" '; + $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension['width'].'px; height:'.$dimension['height'].'px;" '; $picture['original_height'] = $dimension[0]; $picture['original_width'] = $dimension[1]; } diff --git a/main/install/index.php b/main/install/index.php index 181ca5301b..c74ee837d6 100755 --- a/main/install/index.php +++ b/main/install/index.php @@ -702,10 +702,7 @@ if ($_POST['step2']) { if ($installType == 'update') { require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; - require_once api_get_path(LIBRARY_PATH).'image.lib.php'; - remove_memory_and_time_limits(); - database_server_connect(); // Initialization of the database connection encoding intentionaly is not done. // This is the old style for connecting to the database server, that is implemented here. diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index f7b7bc4c7e..41caace442 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -405,8 +405,8 @@ if (!empty ($_GET['student'])) { $image_file = $image_array['dir'] . $image_array['file']; $big_image = $image_array['dir'] . 'big_' . $image_array['file']; $big_image_size = api_getimagesize($big_image); - $big_image_width = $big_image_size[0]; - $big_image_height = $big_image_size[1]; + $big_image_width = $big_image_size['width']; + $big_image_height = $big_image_size['height']; $url_big_image = $big_image . '?rnd=' . time(); $img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' . 'alt="' . api_get_person_name($info_user['firstname'], $info_user['lastname']) . '" ' . diff --git a/main/mySpace/user_add.php b/main/mySpace/user_add.php index d07ea74703..c474a6bd6c 100755 --- a/main/mySpace/user_add.php +++ b/main/mySpace/user_add.php @@ -12,7 +12,6 @@ require_once $libpath.'fileManage.lib.php'; require_once $libpath.'fileUpload.lib.php'; require_once $libpath.'usermanager.lib.php'; require_once $libpath.'formvalidator/FormValidator.class.php'; -require_once $libpath.'image.lib.php'; require_once $libpath.'mail.lib.inc.php'; // user permissions diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 46df5c6a68..86be473022 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -8644,62 +8644,29 @@ EOD; $new_file_name = uniqid('') . '.' . $file_extension; $new_path = $updir . '/' . $new_file_name; - //$result = @move_uploaded_file($image_array['tmp_name'], $new_path); - // Resize the image. - include_once api_get_path(LIBRARY_PATH).'image.lib.php'; - $temp = new image($image_array['tmp_name']); - $picture_infos = @getimagesize($image_array['tmp_name']); // $picture_infos[0]-> width - if ($picture_infos[0] > 104) { + // Resize the image. + $temp = new Image($image_array['tmp_name']); + $picture_infos = $temp->get_image_info(); + if ($picture_infos['width'] > 104) { $thumbwidth = 104; } else { - $thumbwidth = $picture_infos[0]; + $thumbwidth = $picture_infos['width']; } - if ($picture_infos[1] > 96) { + if ($picture_infos['height'] > 96) { $new_height = 96; } else { - $new_height = $picture_infos[1]; - } - //$new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]); - - $temp->resize($thumbwidth,$new_height, 0); - $type = $picture_infos[2]; - $result = false; - - switch ($type) { - case 2 : - $result = $temp->send_image('JPG', $new_path); - break; - case 3 : - $result = $temp->send_image('PNG', $new_path); - break; - case 1 : - $result = $temp->send_image('GIF', $new_path); - break; - } - - $temp->resize($thumbwidth, $new_height, 0); - $type = $picture_infos[2]; - $result = false; - - switch ($type) { - case 2 : - $result = $temp->send_image('JPG', $new_path); - break; - case 3 : - $result = $temp->send_image('PNG', $new_path); - break; - case 1 : - $result = $temp->send_image('GIF', $new_path); - break; - } + $new_height = $picture_infos['height']; + } + $temp->resize($thumbwidth, $new_height, 0); + $result = $temp->send_image($new_path); + // Storing the image filename. if ($result) { $image_moved = true; $this->set_preview_image($new_file_name); return true; } - } } } diff --git a/main/newscorm/openoffice_text_document.class.php b/main/newscorm/openoffice_text_document.class.php index 6b2db0ccb8..2b6f68efa1 100755 --- a/main/newscorm/openoffice_text_document.class.php +++ b/main/newscorm/openoffice_text_document.class.php @@ -294,7 +294,9 @@ class OpenOfficeTextDocument extends OpenofficeDocument { $img_width = $img_width[1]; if (!$defined_width) { - list($img_width, $img_height, $type) = api_getimagesize($this->base_work_dir.$this->created_dir.'/'.$image); + $image_size = api_getimagesize($this->base_work_dir.$this->created_dir.'/'.$image); + $img_width = $image_size['width']; + $img_height = $image_size['height']; $new_width = $max_width - 10; if ($img_width > $new_width) { diff --git a/main/social/friends.php b/main/social/friends.php index 906992ebc3..51e253afe2 100755 --- a/main/social/friends.php +++ b/main/social/friends.php @@ -11,7 +11,6 @@ require '../inc/global.inc.php'; require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; -require_once api_get_path(LIBRARY_PATH).'image.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'social.lib.php'; diff --git a/main/social/group_edit.php b/main/social/group_edit.php index 5f66dd00b7..6a734770a0 100755 --- a/main/social/group_edit.php +++ b/main/social/group_edit.php @@ -22,7 +22,6 @@ require_once $libpath.'fileManage.lib.php'; require_once $libpath.'fileUpload.lib.php'; require_once $libpath.'group_portal_manager.lib.php'; require_once $libpath.'formvalidator/FormValidator.class.php'; -require_once $libpath.'image.lib.php'; require_once $libpath.'mail.lib.inc.php'; require_once $libpath.'social.lib.php'; //jquery thickbox already called from main/inc/header.inc.php @@ -151,15 +150,15 @@ $img_attributes = 'src="'.$image_file.'?rand='.time().'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" '; -if ($image_size[0] > 300) { //limit display width to 300px +if ($image_size['width'] > 300) { //limit display width to 300px $img_attributes .= 'width="300" '; } // get the path,width and height from original picture $big_image = $image_dir.'big_'.$image; $big_image_size = api_getimagesize($big_image); -$big_image_width = $big_image_size[0]; -$big_image_height = $big_image_size[1]; +$big_image_width = $big_image_size['width']; +$big_image_height = $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); /* if ($image == '') { diff --git a/main/social/invitations.php b/main/social/invitations.php index 3153a4834d..5523d5f4ca 100755 --- a/main/social/invitations.php +++ b/main/social/invitations.php @@ -13,7 +13,6 @@ if (api_get_setting('allow_social_tool') !='true') { api_not_allowed(); } -require_once api_get_path(LIBRARY_PATH).'image.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'social.lib.php'; require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php'; diff --git a/main/social/myfiles.php b/main/social/myfiles.php index 90b9a16867..a2f4ee661a 100644 --- a/main/social/myfiles.php +++ b/main/social/myfiles.php @@ -12,7 +12,6 @@ if (api_get_setting('allow_social_tool') !='true') { api_not_allowed(); } -require_once api_get_path(LIBRARY_PATH).'image.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'social.lib.php'; require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php'; diff --git a/main/user/userInfo.php b/main/user/userInfo.php index ba791070e2..099a5f2c3d 100755 --- a/main/user/userInfo.php +++ b/main/user/userInfo.php @@ -349,8 +349,8 @@ elseif ($displayMode == "viewContentEdit") { // get the path,width and height from original picture $big_image = $image_array['dir'].'big_'.$image_array['file']; $big_image_size = api_getimagesize($big_image); - $big_image_width= $big_image_size[0]; - $big_image_height= $big_image_size[1]; + $big_image_width= $big_image_size['width']; + $big_image_height= $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); if ($image_array['file']=='unknown.jpg') { @@ -438,8 +438,8 @@ elseif ($displayMode == "viewContentEdit") { // get the path,width and height from original picture $big_image = $image_array['dir'].'big_'.$image_array['file']; $big_image_size = api_getimagesize($big_image); - $big_image_width= $big_image_size[0]; - $big_image_height= $big_image_size[1]; + $big_image_width= $big_image_size['width']; + $big_image_height= $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); if ($image_array['file']=='unknown.jpg') { diff --git a/tests/main/inc/lib/image.lib.test.php b/tests/main/inc/lib/image.lib.test.php index 2366b23986..2f86ed1961 100755 --- a/tests/main/inc/lib/image.lib.test.php +++ b/tests/main/inc/lib/image.lib.test.php @@ -16,7 +16,7 @@ class TestImage extends UnitTestCase { $this->timage = null; } - public function testAddBackGround() { + /*public function testAddBackGround() { $bgfile=''; $res = image::addbackground($bgfile); $this->assertTrue(is_null($res)); @@ -67,7 +67,7 @@ class TestImage extends UnitTestCase { $res = image::mergelogo($x,$y); $this->assertTrue(is_bool($res)); //var_dump($res); - } + }*/ public function testresize() { $thumbw=''; @@ -85,13 +85,13 @@ class TestImage extends UnitTestCase { //var_dump($res); } - +/* public function testsetfont() { $fontfile=$this->fontfile; $res = image::setfont($fontfile); $this->assertTrue(is_null($res)); //var_dump($res); - } + }*/ /* public function TestDeleteCourse(){ $code = 'COURSETEST'; @@ -109,5 +109,4 @@ class TestImage extends UnitTestCase { } } */ -} -?> +} \ No newline at end of file