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; }
public function createThumbnail($fileName, $source, $destination) { $obj = new stdClass(); $obj->width = EBLOG_MEDIA_ICON_WIDTH; $obj->height = EBLOG_MEDIA_ICON_HEIGHT; $obj->resize = 'within'; require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'image.php'; $imageObj = new EasyBlogImage($fileName, dirname($destination), ''); $imageObj->initDefaultSizes(); }