コード例 #1
0
ファイル: photos.php プロジェクト: joshjim27/jobsglobal
 /**
  *
  * @param type $type
  * @param type $id
  * @param type $sourceX
  * @param type $sourceY
  * @param type $width
  * @param type $height
  */
 public static function updateAvatar($type, $id, $sourceX, $sourceY, $width, $height)
 {
     $filter = JFilterInput::getInstance();
     /* Filter input values */
     $type = $filter->clean($type, 'string');
     $id = $filter->clean($id, 'integer');
     $sourceX = $filter->clean($sourceX, 'float');
     $sourceY = $filter->clean($sourceY, 'float');
     $width = $filter->clean($width, 'float');
     $height = $filter->clean($height, 'float');
     $cTable = JTable::getInstance(ucfirst($type), 'CTable');
     $cTable->load($id);
     $cTable->storage = 'file';
     $cTable->store();
     $srcPath = JPATH_ROOT . '/' . $cTable->avatar;
     $destPath = JPATH_ROOT . '/' . $cTable->thumb;
     /* */
     $config = CFactory::getConfig();
     $avatarFolder = $type != 'profile' && $type != '' ? $type . '/' : '';
     /* Get original image */
     $originalPath = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $avatarFolder . '/' . $type . '-' . JFile::getName($cTable->avatar);
     /**
      * If original image does not exists than we use source image
      * @todo we should get from facebook original avatar file
      */
     if (!JFile::exists($originalPath)) {
         $originalPath = $srcPath;
     }
     $srcPath = str_replace('/', '/', $srcPath);
     $destPath = str_replace('/', '/', $destPath);
     $info = getimagesize($srcPath);
     $destType = $info['mime'];
     $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH;
     $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH;
     /* thumb size */
     $currentWidth = $width;
     $currentHeight = $height;
     /* avatar size */
     $imageMaxWidth = 160;
     $imageMaxHeight = 160;
     /**
      * @todo Should we generate new filename and update into database ?
      */
     /* do avatar resize */
     CImageHelper::resize($originalPath, $srcPath, $destType, $imageMaxWidth, $imageMaxHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
     /* do thumb resize */
     CImageHelper::resize($originalPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
     /**
      * Now we do check and process watermark
      */
     /* Check multiprofile to reapply watermark for thumbnail */
     $my = CFactory::getUser();
     $profileType = $my->getProfileType();
     $multiprofile = JTable::getInstance('MultiProfile', 'CTable');
     $multiprofile->load($profileType);
     $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false;
     if ($useWatermark && $type == 'profile') {
         $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark);
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath);
         list($thumbWidth, $thumbHeight) = getimagesize($destPath);
         list($avatarWidth, $avatarHeight) = getimagesize($srcPath);
         // Avatar Properties
         $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight);
         // The original image file will be removed from the system once it generates a new watermark image.
         CImageHelper::addWatermark($srcPath, $srcPath, $destType, $watermarkPath, $avatarPosition->x, $avatarPosition->y);
         $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
         /* addWatermark into thumbnail */
         CImageHelper::addWatermark($destPath, $destPath, $destType, $watermarkPath, $thumbPosition->x, $thumbPosition->y);
     }
     // we need to update the activity stream of group if applicable, so the cropped image will be updated as well
     if ($type == 'group') {
         $groupParams = new JRegistry($cTable->params);
         $actId = $groupParams->get('avatar_activity_id');
         if ($actId) {
             $act = JTable::getInstance('Activity', 'CTable');
             $act->load($actId);
             $actParams = new JRegistry($act->params);
             $actParams->set('avatar_cropped_thumb', $cTable->avatar);
             $act->params = $actParams->toString();
             $act->store();
         }
     }
     $connectModel = CFactory::getModel('connect');
     // For facebook user, we need to add the watermark back on
     if ($connectModel->isAssociated($my->id) && $config->get('fbwatermark') && $type == 'profile') {
         list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON);
         CImageHelper::addWatermark($destPath, $destPath, $destType, FACEBOOK_FAVICON, $destWidth - $watermarkWidth, $destHeight - $watermarkHeight);
     }
 }
コード例 #2
0
ファイル: image.php プロジェクト: bizanto/Hooked
 /**
  * Method to create a thumbnail for an image
  *
  * @param	$srcPath	The original source of the image.
  * @param	$destPath	The destination path for the image
  * @param	$destType	The destination image type.
  * @param	$destWidth	The width of the thumbnail.
  * @param	$destHeight	The height of the thumbnail.
  * 
  * @return	bool		True on success.
  */
 public static function createThumb($srcPath, $destPath, $destType, $destWidth = 64, $destHeight = 64)
 {
     // Get the image size for the current original photo
     list($currentWidth, $currentHeight) = getimagesize($srcPath);
     $config = CFactory::getConfig();
     $jconfig = JFactory::getConfig();
     // Find the correct x/y offset and source width/height. Crop the image squarely, at the center.
     if ($currentWidth == $currentHeight) {
         $sourceX = 0;
         $sourceY = 0;
     } else {
         if ($currentWidth > $currentHeight) {
             //$sourceX			= intval( ( $currentWidth - $currentHeight ) / 2 );
             $sourceX = 0;
             /* HTGMOD */
             $sourceY = 0;
             $currentWidth = $currentHeight;
         } else {
             $sourceX = 0;
             $sourceY = intval(($currentHeight - $currentWidth) / 2);
             $currentHeight = $currentWidth;
         }
     }
     $imageEngine = $config->get('imageengine');
     $magickPath = $config->get('magickPath');
     // Use imageMagick if available
     if (class_exists('Imagick') && ($imageEngine == 'auto' || $imageEngine == 'imagick')) {
         // Put the new image in temporary dest path, and move them using
         // Joomla API to ensure new folder is created
         $tempFilename = $jconfig->getValue('tmp_path') . DS . md5($destPath);
         $thumb = new Imagick();
         $thumb->readImage($srcPath);
         $thumb->cropThumbnailImage($destWidth, $destHeight);
         $thumb->writeImage($tempFilename);
         $thumb->clear();
         $thumb->destroy();
         // Move to the correct path
         JFile::move($tempFilename, $destPath);
         return true;
     } else {
         if (!empty($magickPath) && !class_exists('Imagick')) {
             // Execute the command to resize. In windows, the commands are executed differently.
             if (JString::strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                 $file = rtrim($config->get('magickPath'), '/') . DS . 'convert.exe';
                 $command = '"' . rtrim($config->get('magickPath'), '/') . DS . 'convert.exe"';
             } else {
                 $file = rtrim($config->get('magickPath'), '/') . DS . 'convert';
                 $command = '"' . rtrim($config->get('magickPath'), '/') . DS . 'convert"';
             }
             if (JFile::exists($file) && function_exists('exec')) {
                 $execute = $command . ' -resize ' . $destWidth . 'x' . $destHeight . ' ' . $srcPath . ' ' . $destPath;
                 exec($execute);
                 // Test if the files are created, otherwise we know the exec failed.
                 if (JFile::exists($destPath)) {
                     return true;
                 }
             }
         }
     }
     // IF all else fails, we try to use GD
     return CImageHelper::resize($srcPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
 }
コード例 #3
0
ファイル: themeprofile.php プロジェクト: Jougito/DynWeb
 /**
  *  Save the profile information
  */
 public function apply()
 {
     CommunityLicenseHelper::_();
     JRequest::checkToken() or jexit(JText::_('COM_COMMUNITY_INVALID_TOKEN'));
     $mainframe = JFactory::getApplication();
     $jinput = $mainframe->input;
     if (JString::strtoupper($jinput->getMethod()) != 'POST') {
         $mainframe->redirect('index.php?option=com_community&view=themeprofile', JText::_('COM_COMMUNITY_PERMISSION_DENIED'), 'error');
     }
     $settings = $jinput->post->get('settings', array(), 'array');
     $configs = $jinput->post->get('config', null, 'array');
     // save the config first
     $model = $this->getModel('Configuration');
     if (!empty($configs)) {
         $model->save($configs);
     }
     // First, parse the Cover Info fields and unset the extra keys
     $helper = new CommunityThemeHelper();
     $settings['tagline'] = $helper->prepareCoverInfo($settings);
     // Handle image uploads
     #echo "<pre>";var_dump($post);die();
     $images['default-cover'] = $jinput->files->get('default-cover-new', '', 'NONE');
     $images['default-cover-male'] = $jinput->files->get('default-cover-male-new', '', 'NONE');
     $images['default-cover-female'] = $jinput->files->get('default-cover-female-new', '', 'NONE');
     $images['default-male-avatar'] = $jinput->files->get('default-male-avatar-new', '', 'NONE');
     $images['default-female-avatar'] = $jinput->files->get('default-female-avatar-new', '', 'NONE');
     $images['default-general-avatar'] = $jinput->files->get('default-general-avatar-new', '', 'NONE');
     foreach ($images as $key => $image) {
         if (!empty($image['tmp_name']) && isset($image['name']) && !empty($image['name'])) {
             try {
                 CImageHelper::autorotate($image['tmp_name']);
             } catch (Exception $e) {
             }
             $imagePath = COMMUNITY_PATH_ASSETS;
             // same as the image path
             //check the file extension first and only allow jpg or png
             $ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION));
             if (!in_array($ext, array('jpg', 'jpeg', 'png')) || $image['type'] != 'image/png' && $image['type'] != 'image/jpeg') {
                 $mainframe->redirect('index.php?option=com_community&view=themeprofile', JText::_('COM_COMMUNITY_THEME_IMAGE_ERROR'), 'error');
             }
             $imageJpg = $imagePath . '/' . $key . '.jpg';
             $imagePng = $imagePath . '/' . $key . '.png';
             //check if existing image exist, if yes, delete it
             if (file_exists($imageJpg)) {
                 unlink($imageJpg);
             }
             if (file_exists($imagePng)) {
                 unlink($imagePng);
             }
             //let move the tmp image to the actual path
             $finalPath = $imagePath . $key . '.' . $ext;
             $finalPathThumb = $imagePath . $key . '-thumb.' . $ext;
             move_uploaded_file($image['tmp_name'], $finalPath);
             require_once JPATH_ROOT . "/components/com_community/helpers/image.php";
             if (strstr($key, 'avatar')) {
                 //avatars
                 // Check 1:1
                 $size = CImageHelper::getSize($finalPath);
                 if ($size->height != $size->width) {
                     $message = JTEXT::_('COM_COMMUNITY_THEME_AVATAR_RESIZED');
                 }
                 CImageHelper::resize($finalPath, $finalPath, "image/{$ext}", 160, 160);
                 // thumb
                 CImageHelper::resize($finalPath, $finalPathThumb, "image/{$ext}", 64, 64);
             } else {
                 // other images
                 CImageHelper::resizeProportional($finalPath, $finalPath, "image/{$ext}", 1000, 1000);
             }
             $settings[$key] = $ext;
         }
     }
     // Parse the rest of the settings afterwards
     $helper->parseSettings($settings, 'profile');
     // There isn't much that can go wrong, no validation required
     if (!$message) {
         $message = JText::_('COM_COMMUNITY_THEME_PROFILE_UPDATED');
     }
     $mainframe->redirect('index.php?option=com_community&view=themeprofile', $message, 'message');
 }
コード例 #4
0
ファイル: profile.php プロジェクト: bizanto/Hooked
 /**
  * Resize user's thumbnail from the source image
  * 
  * @param Object $imgObj
  * @param String $src
  *
  */
 function ajaxUpdateThumbnail($sourceX, $sourceY, $width, $height, $hideSave = false)
 {
     // Fetch the thumbnail remotely. This is necessary since the user
     // profile picture might not be stored locally
     $objResponse = new JAXResponse();
     $my = CFactory::getUser();
     $guest = CFactory::getUser(0);
     if ($my->id && $guest->_avatar != $my->_avatar) {
         // Resize it
         $srcPath = JPATH_ROOT . DS . $my->_avatar;
         $destPath = JPATH_ROOT . DS . $my->_thumb;
         $srcPath = str_replace('/', DS, $srcPath);
         $destPath = str_replace('/', DS, $destPath);
         $info = getimagesize($srcPath);
         $destType = $info['mime'];
         $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH;
         $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH;
         $currentWidth = $width;
         $currentHeight = $height;
         // @todo: we should just delete the old one and use a new path
         CFactory::load('helpers', 'image');
         CImageHelper::resize($srcPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
         $objResponse->addScriptCall('refreshThumbnail');
         $objResponse->addScriptCall('joms.jQuery("#update-thumbnail-guide").css("display","block");');
         if ($hideSave == "true") {
             $objResponse->addScriptCall('saveThumbnail();');
             $objResponse->addScriptCall('joms.jQuery("#update-thumbnail").html("' . JText::_('CC UPDATE THUMBNAIL') . '");');
         } else {
             $objResponse->addScriptCall('joms.jQuery("#update-thumbnail").html("' . JText::_('CC THUMBNAIL SAVE') . '");');
         }
     } else {
         return $this->ajaxBlockUnregister();
     }
     return $objResponse->sendResponse();
 }
コード例 #5
0
ファイル: profile.php プロジェクト: Simarpreet05/joomla
 /**
  * Resize user's thumbnail from the source image
  * 
  * @param Object $imgObj
  * @param String $src
  *
  */
 public function ajaxUpdateThumbnail($sourceX, $sourceY, $width, $height, $hideSave = false)
 {
     $filter = JFilterInput::getInstance();
     $sourceX = $filter->clean($sourceX, 'float');
     $sourceY = $filter->clean($sourceY, 'float');
     $width = $filter->clean($width, 'float');
     $height = $filter->clean($height, 'float');
     $hideSave = $filter->clean($hideSave, 'bool');
     // Fetch the thumbnail remotely. This is necessary since the user
     // profile picture might not be stored locally
     $objResponse = new JAXResponse();
     $my = CFactory::getUser();
     $guest = CFactory::getUser(0);
     if ($my->id && $guest->_avatar != $my->_avatar) {
         // Resize it
         $srcPath = JPATH_ROOT . DS . $my->_avatar;
         $destPath = JPATH_ROOT . DS . $my->_thumb;
         $srcPath = str_replace('/', DS, $srcPath);
         $destPath = str_replace('/', DS, $destPath);
         $info = getimagesize($srcPath);
         $destType = $info['mime'];
         $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH;
         $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH;
         $currentWidth = $width;
         $currentHeight = $height;
         // @todo: we should just delete the old one and use a new path
         CFactory::load('helpers', 'image');
         CImageHelper::resize($srcPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
         $connectModel = CFactory::getModel('connect');
         // For facebook user, we need to add the watermark back on
         if ($connectModel->isAssociated($my->id) && $config->get('fbwatermark')) {
             list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON);
             CImageHelper::addWatermark($destPath, $destPath, $destType, FACEBOOK_FAVICON, $destWidth - $watermarkWidth, $destHeight - $watermarkHeight);
         }
         $objResponse->addScriptCall('refreshThumbnail');
     } else {
         return $this->ajaxBlockUnregister();
     }
     return $objResponse->sendResponse();
 }
コード例 #6
0
ファイル: photos.php プロジェクト: Simarpreet05/joomla
 public function ajaxUpdateThumbnail($type, $id, $sourceX, $sourceY, $width, $height)
 {
     $filter = JFilterInput::getInstance();
     $type = $filter->clean($type, 'string');
     $id = $filter->clean($id, 'integer');
     $sourceX = $filter->clean($sourceX, 'float');
     $sourceY = $filter->clean($sourceY, 'float');
     $width = $filter->clean($width, 'float');
     $height = $filter->clean($height, 'float');
     $objResponse = new JAXResponse();
     $cTable =& JTable::getInstance(ucfirst($type), 'CTable');
     $cTable->load($id);
     $srcPath = JPATH_ROOT . DS . $cTable->avatar;
     $destPath = JPATH_ROOT . DS . $cTable->thumb;
     $srcPath = str_replace('/', DS, $srcPath);
     $destPath = str_replace('/', DS, $destPath);
     $info = getimagesize($srcPath);
     $destType = $info['mime'];
     $destWidth = COMMUNITY_SMALL_AVATAR_WIDTH;
     $destHeight = COMMUNITY_SMALL_AVATAR_WIDTH;
     $currentWidth = $width;
     $currentHeight = $height;
     CFactory::load('helpers', 'image');
     CImageHelper::resize($srcPath, $destPath, $destType, $destWidth, $destHeight, $sourceX, $sourceY, $currentWidth, $currentHeight);
     return $objResponse->sendResponse();
 }