|
|
@ -3114,9 +3114,10 @@ class CourseManager |
|
|
|
* @param string Course code |
|
|
|
* @param string Course code |
|
|
|
* @param string File name |
|
|
|
* @param string File name |
|
|
|
* @param string The full system name of the image from which course picture will be created. |
|
|
|
* @param string The full system name of the image from which course picture will be created. |
|
|
|
|
|
|
|
* @param string $cropParameters Optional string that contents "x,y,width,height" of a cropped image format |
|
|
|
* @return bool Returns the resulting. In case of internal error or negative validation returns FALSE. |
|
|
|
* @return bool Returns the resulting. In case of internal error or negative validation returns FALSE. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static function update_course_picture($course_code, $filename, $source_file = null) |
|
|
|
public static function update_course_picture($course_code, $filename, $source_file = null, $cropParameters = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
// course path |
|
|
|
// course path |
|
|
@ -3132,18 +3133,20 @@ class CourseManager |
|
|
|
unlink($course_medium_image); |
|
|
|
unlink($course_medium_image); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$my_course_image = new Image($source_file); |
|
|
|
//Crop the image to adjust 4:3 ratio |
|
|
|
$result = $my_course_image->send_image($course_image, -1, 'png'); |
|
|
|
$croppedImage = self::crop_image($source_file, $cropParameters); |
|
|
|
// Resize image to 100x85 (should be 85x85 but 100x85 visually gives |
|
|
|
$croppedPath = $croppedImage->image_wrapper->path; |
|
|
|
// better results for most images people put as course icon) |
|
|
|
|
|
|
|
if ($result) { |
|
|
|
//Resize the images in two formats |
|
|
|
$medium = new Image($course_image); |
|
|
|
$medium = self::resize_picture($croppedPath, 85); |
|
|
|
//$picture_infos = $medium->get_image_size(); |
|
|
|
$normal = self::resize_picture($croppedPath, 300); |
|
|
|
$medium->resize(100, 85, 0, false); |
|
|
|
|
|
|
|
$medium->send_image($store_path . '/course-pic85x85.png', -1, 'png'); |
|
|
|
$medium->send_image($course_medium_image, -1, 'png'); |
|
|
|
} |
|
|
|
$result = $normal->send_image($course_image, -1, 'png'); |
|
|
|
|
|
|
|
$result = $medium && $medium->send_image($course_medium_image, -1, 'png') && |
|
|
|
return $result; |
|
|
|
$normal && $normal->send_image($course_image, -1, 'png'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $result ? $result : false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -5375,6 +5378,67 @@ class CourseManager |
|
|
|
|
|
|
|
|
|
|
|
return $send_to; |
|
|
|
return $send_to; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Resize a picture |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string file picture |
|
|
|
|
|
|
|
* @param int size in pixels |
|
|
|
|
|
|
|
* @todo move this function somewhere else image.lib? |
|
|
|
|
|
|
|
* @return obj image object |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function resize_picture($file, $max_size_for_picture) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$temp = false; |
|
|
|
|
|
|
|
if (file_exists($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 |
|
|
|
|
|
|
|
$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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Crop a Image |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @author José Loguercio <jose.loguercio@beeznest.com> |
|
|
|
|
|
|
|
* @param string file picture |
|
|
|
|
|
|
|
* @param string crop Parameters (x, y, width, height) |
|
|
|
|
|
|
|
* @return obj image object |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function crop_image($file, $cropParameters) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$image = false; |
|
|
|
|
|
|
|
if (file_exists($file)) { |
|
|
|
|
|
|
|
$image = new Image($file); |
|
|
|
|
|
|
|
$image_size = $image->get_image_size($file); |
|
|
|
|
|
|
|
$src_width = $image_size['width']; |
|
|
|
|
|
|
|
$src_height = $image_size['height']; |
|
|
|
|
|
|
|
$cropParameters = explode(",", $cropParameters); |
|
|
|
|
|
|
|
$x = intval($cropParameters[0]); |
|
|
|
|
|
|
|
$y = intval($cropParameters[1]); |
|
|
|
|
|
|
|
$width = intval($cropParameters[2]); |
|
|
|
|
|
|
|
$height = intval($cropParameters[3]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$image->crop($x, $y, $width, $height, $src_width, $src_height); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $image; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* this function shows the form for sending a message to a specific group or user. |
|
|
|
* this function shows the form for sending a message to a specific group or user. |
|
|
|