|
|
|
@ -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': |
|
|
|
|