public function upload($folder, $filename, $file, $baseUri, $storagePath, $subfolder = '') { require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'easysimpleimage.php'; $config = EasyBlogHelper::getConfig(); $user = JFactory::getUser(); if (isset($file['name'])) { if ($config->get('main_resize_original_image')) { $maxWidth = $config->get('main_original_image_width'); $maxHeight = $config->get('main_original_image_height'); $image = new EasySimpleImage(); $image->load($file['tmp_name']); $image->resizeWithin($maxWidth, $maxHeight); $uploadStatus = $image->save($storagePath, $image->image_type, $config->get('main_original_image_quality')); } else { $uploadStatus = JFile::upload($file['tmp_name'], $storagePath); } if ($uploadStatus) { // $activity = new stdClass(); // $activity->actor_id = $user->id; // $activity->target_id = '0'; // $activity->context_type = 'photo'; // $activity->context_id = '0'; // $activity->verb = 'upload'; // EasyBlogHelper::activityLog( $activity ); } // @task: thumbnail's file name $storagePathThumb = JPath::clean($folder . DIRECTORY_SEPARATOR . EBLOG_MEDIA_THUMBNAIL_PREFIX . $filename); // @rule: Generate a thumbnail for each uploaded images $image = new EasySimpleImage(); $image->load($storagePath); $image->resizeWithin($config->get('main_thumbnail_width'), $config->get('main_thumbnail_height')); $image->save($storagePathThumb, $image->image_type, $config->get('main_thumbnail_quality')); if (!$uploadStatus) { return $this->getMessageObj(EBLOG_MEDIA_PERMISSION_ERROR, JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_ERROR')); } else { // file uploaded. Now we test if the index.html was there or not. // if not, copy from easyblog root into this folder if (!JFile::exists($folder . DIRECTORY_SEPARATOR . 'index.html')) { $targetFile = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'index.html'; $destFile = $folder . DIRECTORY_SEPARATOR . 'index.html'; if (JFile::exists($targetFile)) { JFile::copy($targetFile, $destFile); } } return self::getMessageObj(EBLOG_MEDIA_UPLOAD_SUCCESS, JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS'), EasyBlogHelper::getHelper('ImageData')->getObject($folder, $filename, $baseUri, $subfolder)); } } else { return self::getMessageObj(EBLOG_MEDIA_TRANSPORT_ERROR, JText::_('COM_EASYBLOG_MEDIA_MANAGER_NO_UPLOAD_FILE')); } return $response; }
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; }
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; }