Feature #5142 make thumbnails from ajaxfilemanager and prepare delete orphans

skala
Juan Carlos Raña 13 years ago
parent b6d8ec89f1
commit ac6c0e4361
  1. 68
      main/document/slideshow.php
  2. 124
      main/inc/lib/fckeditor/editor/plugins/ajaxfilemanager/_ajax_get_thumbnail_listing.php

@ -182,30 +182,51 @@ if (isset($_SESSION["image_resizing"]) && $_SESSION["image_resizing"] == "resiz
$image_tag = array ();
if ($slide_id == 'all') {
// Create the template_thumbnails folder (if no exist)
if (!$sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/') {
@mkdir($sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/', api_get_permissions_for_new_directories());
}
// Config thumbnails
$row_items = 4;
$row_items = 4;//only in slideshow.php
$allowed_thumbnail_types = array('jpg','jpeg','gif','png');
$max_thumbnail_width = 100;
$max_thumbnail_height = 100;
$png_compression = 0;//0(none)-9
$jpg_quality = 75;//from 0 to 100 (default is 75). More queality less compression
$jpg_quality = 75;//from 0 to 100 (default is 75). More quality less compression
$directory_thumbnails=$sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/';
// Create the template_thumbnails folder (if no exist)
if (!$directory_thumbnails) {
@mkdir($directory_thumbnails, api_get_permissions_for_new_directories());
}
/*
//
//disabled by now, because automatic mode is heavy for server (scandir), only manual
//
// Delete orphaned thumbnails
$directory_images=$sys_course_path.$_course['path'].'/document'.$folder;
$all_thumbnails = scandir($directory_thumbnails);
$all_files = scandir($directory_images);
foreach ($all_thumbnails as $check_thumb) {
$temp_filename=substr($check_thumb,1);//erase the first dot in file, and translate .. to .
if ($temp_filename=='.') {
continue; //need because scandir also return . and .. simbols
}
if(in_array($filename, $all_files)==false) {
unlink($directory_thumbnails.'.'.$temp_filename);
}
}
*/
// check files and thumbnails
if (is_array($image_files_only)) {
foreach ($image_files_only as $one_image_file) {
$image = $sys_course_path.$_course['path'].'/document'.$folder.$one_image_file;
$image_thumbnail= $sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/.'.$one_image_file;
$image_thumbnail= $directory_thumbnails.'.'.$one_image_file;
if (file_exists($image)) {
//check thumbnail
$imagetype = explode(".", $image);
$imagetype = strtolower($imagetype[count($imagetype)-1]);
$imagetype = strtolower($imagetype[count($imagetype)-1]);//or check $imagetype = image_type_to_extension(exif_imagetype($image), false);
if(in_array($imagetype,$allowed_thumbnail_types)) {
@ -219,6 +240,9 @@ if ($slide_id == 'all') {
case 'jpg':
$source_img = imagecreatefromjpeg($image);
break;
case 'jpeg':
$source_img = imagecreatefromjpeg($image);
break;
case 'png':
$source_img = imagecreatefrompng($image);
break;
@ -249,15 +273,19 @@ if ($slide_id == 'all') {
//resampled image
imagecopyresampled($crop,$source_img,0,0,0,0,$new_thumbnail_size['width'],$new_thumbnail_size['height'],$original_image_size['width'],$original_image_size['height']);
if($imagetype == ("jpg" || "jpeg")) {
imagejpeg($crop,$image_thumbnail,$jpg_quality);
}
if($imagetype == "png") {
imagepng($crop,$image_thumbnail,$png_compression);
}
if($imagetype == "gif"){
imagegif($crop,$image_thumbnail);
switch($imagetype) {
case 'gif':
imagegif($crop,$image_thumbnail);
break;
case 'jpg':
imagejpeg($crop,$image_thumbnail,$jpg_quality);
break;
case 'jpeg':
imagejpeg($crop,$image_thumbnail,$jpg_quality);
break;
case 'png':
imagepng($crop,$image_thumbnail,$png_compression);
break;
}
//clean memory

@ -65,16 +65,126 @@ foreach ($fileList as $file) {
switch($file['cssClass']) {
case 'filePicture':
echo '<a id="thumbUrl' . $count . '" rel="thumbPhotos" href="' . $file['public_path'] . '">';
///////////////////////////////////////// Chamilo create thumbnail
//improve for Chamilo load thumbnails from disk
$thumbnail_disk= dirname($file['path']).'/.thumbs/.'.basename($file['path']);
//setting
$allowed_thumbnail_types = array('jpg','jpeg','gif','png');
$max_thumbnail_width = 100;
$max_thumbnail_height = 100;
$png_compression = 0;//0(none)-9
$jpg_quality = 75;//from 0 to 100 (default is 75). More quality less compression
if (file_exists($thumbnail_disk)) {
echo '<img src="' . appendQueryString($thumbnailBaseUrl, ' path=' . base64_encode($thumbnail_disk)) . '" id="thumbImg' . $count . '"></a>' . "\n";
}
else {
echo '<img src="' . appendQueryString($thumbnailBaseUrl, ' path=' . base64_encode($file['path'])) . '" id="thumbImg' . $count . '"></a>' . "\n";
$directory_thumbnails=dirname($file['path']).'/.thumbs/';
if (!$directory_thumbnails) {
@mkdir($directory_thumbnails, api_get_permissions_for_new_directories());
}
/*
//
//disabled by now, because automatic mode is heavy for server (scandir), only manual please
//
// Delete orphaned thumbnails
$directory_images=dirname($file['path']);
$all_thumbnails = scandir($directory_thumbnails);
$all_files = scandir($directory_images);
foreach ($all_thumbnails as $check_thumb) {
$temp_filename=substr($check_thumb,1);//erase the first dot in file, and translate .. to .
if ($temp_filename=='.') {
continue; //need because scandir also return . and .. simbols
}
if(in_array($filename, $all_files)==false) {
unlink($directory_thumbnails.'.'.$temp_filename);
}
}
*/
//create thumbnails
$image=$file['path'];
$image_thumbnail= $directory_thumbnails.'.'.basename($file['path']);
if (file_exists($image)) {
//check thumbnail
$imagetype = explode(".", $image);
$imagetype = strtolower($imagetype[count($imagetype)-1]);//or check $imagetype = image_type_to_extension(exif_imagetype($image), false);
if(in_array($imagetype,$allowed_thumbnail_types)) {
if (!file_exists($image_thumbnail)){
$original_image_size = api_getimagesize($image);
switch($imagetype) {
case 'gif':
$source_img = imagecreatefromgif($image);
break;
case 'jpg':
$source_img = imagecreatefromjpeg($image);
break;
case 'jpeg':
$source_img = imagecreatefromjpeg($image);
break;
case 'png':
$source_img = imagecreatefrompng($image);
break;
}
$new_thumbnail_size = api_calculate_image_size($original_image_size['width'], $original_image_size['height'], $max_thumbnail_width, $max_thumbnail_height);
$crop = imagecreatetruecolor($new_thumbnail_size['width'], $new_thumbnail_size['height']);
// preserve transparency
if($imagetype == "png"){
imagesavealpha($crop, true);
$color = imagecolorallocatealpha($crop,0x00,0x00,0x00,127);
imagefill($crop, 0, 0, $color);
}
if($imagetype == "gif"){
$transindex = imagecolortransparent($image);
//GIF89a for transparent and anim (first clip), either GIF87a
if($transindex >= 0){
$transcol = imagecolorsforindex($image, $transindex);
$transindex = imagecolorallocatealpha($crop, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
imagefill($crop, 0, 0, $transindex);
imagecolortransparent($crop, $transindex);
}
}
//resampled image
imagecopyresampled($crop,$source_img,0,0,0,0,$new_thumbnail_size['width'],$new_thumbnail_size['height'],$original_image_size['width'],$original_image_size['height']);
switch($imagetype) {
case 'gif':
imagegif($crop,$image_thumbnail);
break;
case 'jpg':
imagejpeg($crop,$image_thumbnail,$jpg_quality);
break;
case 'jpeg':
imagejpeg($crop,$image_thumbnail,$jpg_quality);
break;
case 'png':
imagepng($crop,$image_thumbnail,$png_compression);
break;
}
//clean memory
imagedestroy($crop);
}//end exist thumbnail
//show thumbnail
echo '<img src="' . appendQueryString($thumbnailBaseUrl, ' path=' . base64_encode($image_thumbnail)) . '" id="thumbImg' . $count . '"></a>' . "\n";
}
else{
echo '<img src="' . appendQueryString($thumbnailBaseUrl, ' path=' . base64_encode($file['path'])) . '" id="thumbImg' . $count . '"></a>' . "\n";
}//end allowed image types
}//end if exist file image
///////////////////////////////////////// End Chamilo create thumbnail
break;
case 'fileFlash':
case 'fileVideo':

Loading…
Cancel
Save