Ejemplo n.º 1
0
 public function createImage($params, $storeTo)
 {
     // @task: Retrieve the configs.
     $config = EasyBlogHelper::getConfig();
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'easysimpleimage.php';
     // @rule: Generate a thumbnail for each uploaded images
     $image = new EasySimpleImage();
     $image->load($this->original);
     $resizeType = isset($params->resize) ? $params->resize : EBLOG_IMAGE_DEFAULT_RESIZE;
     $originalWidth = $image->getWidth();
     $originalHeight = $image->getHeight();
     // If quality is not given, use default quality given in configuration
     if (!isset($params->quality)) {
         $params->quality = $config->get('main_image_quality');
     }
     // TODO: This should be done in the crop function itself
     if ($resizeType == 'crop') {
         if ($originalWidth < $params->width || $originalHeight < $params->height) {
             $resizeType = 'fill';
         }
     }
     switch ($resizeType) {
         case 'crop':
             $image->crop($params->width, $params->height);
             break;
         case 'fit':
             $image->resizeToFit($params->width, $params->height);
             break;
         case 'within':
             $image->resizeWithin($params->width, $params->height);
             break;
         case 'fill':
         default:
             $image->resizeToFill($params->width, $params->height);
             break;
     }
     $image->save($storeTo, $image->image_type, $params->quality);
     return true;
 }
Ejemplo n.º 2
0
 public static function upload($storagePath, $fileName, $fileItem)
 {
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'easysimpleimage.php';
     $cfg = EasyBlogHelper::getConfig();
     $user = JFactory::getUser();
     // @task: Resize original image if necessary. Otherwise, just copy the file over.
     $originalStorage = JPath::clean($storagePath . DIRECTORY_SEPARATOR . $fileName);
     // check if folder not exists, then we need to create first or else the copy operation will fail.
     if (!JFolder::exists($storagePath)) {
         JFolder::create($storagePath);
     }
     $image = new EasySimpleImage();
     $image->load($fileItem['tmp_name']);
     if ($cfg->get('main_resize_original_image')) {
         // @task: Get the maximum width / height for the original images.
         $maxWidth = $cfg->get('main_original_image_width');
         $maxHeight = $cfg->get('main_original_image_height');
         if ($image->getWidth() > $maxWidth || $image->getHeight() > $maxHeight) {
             $image->resizeWithin($maxWidth, $maxHeight);
             $state = $image->save($originalStorage, $image->image_type, $cfg->get('main_original_image_quality'));
         } else {
             $state = JFile::copy($fileItem['tmp_name'], $originalStorage);
         }
     } else {
         // @task: Since no resizing is required, just upload the whole file.
         if ($image->orientationFixed) {
             $state = $image->save($originalStorage, $image->image_type, $cfg->get('main_original_image_quality'));
         } else {
             $state = JFile::copy($fileItem['tmp_name'], $originalStorage);
         }
     }
     // @task: Once the original storage has been taken care off, we need to find the sizes that are required to be resized.
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'image.php';
     $imageObj = new EasyBlogImage($fileName, $storagePath, '');
     // @TODO: Cater for error checking here.
     $imageObj->initDefaultSizes();
     if ($state === false) {
         return JText::_('COM_EASYBLOG_MM_UNABLE_TO_SAVE_FILE');
     }
     return true;
 }