Example #1
0
 function createFileThumbnail($file_original, $file_thumbnail, $size, $frontUpload = 0)
 {
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     // Watermark
     $watermarkParams['create'] = $paramsC->get('create_watermark', 0);
     $watermarkParams['x'] = $paramsC->get('watermark_position_x', 'center');
     $watermarkParams['y'] = $paramsC->get('watermark_position_y', 'middle');
     // Crop or not
     $crop_thumbnail = $paramsC->get('crop_thumbnail', 5);
     $crop = null;
     switch ($size) {
         case 'small':
             if ($crop_thumbnail == 3 || $crop_thumbnail == 5 || $crop_thumbnail == 6 || $crop_thumbnail == 7) {
                 $crop = 1;
             }
             break;
         case 'medium':
             if ($crop_thumbnail == 2 || $crop_thumbnail == 4 || $crop_thumbnail == 5 || $crop_thumbnail == 7) {
                 $crop = 1;
             }
             break;
         case 'large':
         default:
             if ($crop_thumbnail == 1 || $crop_thumbnail == 4 || $crop_thumbnail == 6 || $crop_thumbnail == 7) {
                 $crop = 1;
             }
             break;
     }
     $enable_thumb_creation = $paramsC->get('enable_thumb_creation', 1);
     // disable or enable the thumbnail creation
     if ($enable_thumb_creation == 1) {
         $file_original = str_replace(DS, '/', JPath::clean($file_original));
         $file_thumbnail = str_replace(DS, '/', JPath::clean($file_thumbnail));
         $file_resize = PhocaGalleryHelper::getFileResize($size);
         if (JFile::exists($file_original)) {
             //file doesn't exist, create thumbnail
             if (!JFile::exists($file_thumbnail)) {
                 $createdThumb = 'Error4';
                 //Don't do thumbnail if the file is smaller (width, height) than the possible thumbnail
                 list($width, $height) = GetImageSize($file_original);
                 //larger
                 if ($width > $file_resize['width'] || $height > $file_resize['height']) {
                     $createdThumb = PhocaGalleryHelper::imageMagic($file_original, $file_thumbnail, $file_resize['width'], $file_resize['height'], $crop, null, $watermarkParams, $frontUpload);
                 } else {
                     $createdThumb = PhocaGalleryHelper::imageMagic($file_original, $file_thumbnail, $width, $height, $crop, null, $watermarkParams, $frontUpload);
                 }
                 return $createdThumb;
                 //thumbnail now created
             } else {
                 return 'ThumbnailExists';
                 //thumbnail exists
             }
         } else {
             return 'ErrorFileOriginalNotExists';
         }
         return 'Error3';
     } else {
         return 'DisabledThumbCreation';
         // User have disabled the thumbanil creation e.g. because of error
     }
 }