当前位置: 首页>>代码示例>>PHP>>正文


PHP SimpleImage::resizeOriginal方法代码示例

本文整理汇总了PHP中SimpleImage::resizeOriginal方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleImage::resizeOriginal方法的具体用法?PHP SimpleImage::resizeOriginal怎么用?PHP SimpleImage::resizeOriginal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleImage的用法示例。


在下文中一共展示了SimpleImage::resizeOriginal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uploadAvatar


//.........这里部分代码省略.........
     $file['name'] = $my->id . '_' . JFile::makeSafe(md5($file['name'] . $date->toMySQL())) . '.' . strtolower($file_ext);
     if (isset($file['name'])) {
         $target_file_path = $upload_path;
         $relative_target_file = $rel_upload_path . '/' . $file['name'];
         $target_file = JPath::clean($target_file_path . '/' . JFile::makeSafe($file['name']));
         $original = JPath::clean($target_file_path . '/' . 'original_' . JFile::makeSafe($file['name']));
         $isNew = false;
         require_once DISCUSS_HELPERS . '/image.php';
         require_once DISCUSS_CLASSES . '/simpleimage.php';
         if (!DiscussImageHelper::canUpload($file, $err)) {
             if (!$isFromBackend) {
                 DiscussHelper::setMessageQueue(JText::_($err), 'error');
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false));
             } else {
                 // From backend
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::_($err), 'error');
             }
             return;
         }
         if (0 != (int) $file['error']) {
             if (!$isFromBackend) {
                 DiscussHelper::setMessageQueue($file['error'], 'error');
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false));
             } else {
                 //from backend
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), $file['error'], 'error');
             }
             return;
         }
         //rename the file 1st.
         $oldAvatar = $profile->avatar;
         $tempAvatar = '';
         if ($oldAvatar != 'default.png') {
             $session = JFactory::getSession();
             $sessionId = $session->getToken();
             $fileExt = JFile::getExt(JPath::clean($target_file_path . '/' . $oldAvatar));
             $tempAvatar = JPath::clean($target_file_path . '/' . $sessionId . '.' . $fileExt);
             // Test if old original file exists.
             if (JFile::exists($target_file_path . '/original_' . $oldAvatar)) {
                 JFile::delete($target_file_path . '/original_' . $oldAvatar);
             }
             JFile::move($target_file_path . '/' . $oldAvatar, $tempAvatar);
         } else {
             $isNew = true;
         }
         if (JFile::exists($target_file)) {
             if ($oldAvatar != 'default.png') {
                 //rename back to the previous one.
                 JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar);
             }
             if (!$isFromBackend) {
                 DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false));
             } else {
                 //from backend
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
             }
             return;
         }
         if (JFolder::exists($target_file)) {
             if ($oldAvatar != 'default.png') {
                 //rename back to the previous one.
                 JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar);
             }
             if (!$isFromBackend) {
                 DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false));
             } else {
                 //from backend
                 $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error');
             }
             return;
         }
         $configImageWidth = $config->get('layout_avatarwidth', 160);
         $configImageHeight = $config->get('layout_avatarheight', 160);
         $originalImageWidth = $config->get('layout_originalavatarwidth', 400);
         $originalImageHeight = $config->get('layout_originalavatarheight', 400);
         // Copy the original image files over
         $image = new SimpleImage();
         $image->load($file['tmp_name']);
         //$image->resizeToFill( $originalImageWidth , $originalImageHeight );
         // By Kevin Lankhorst
         $image->resizeOriginal($originalImageWidth, $originalImageHeight, $configImageWidth, $configImageHeight);
         $image->save($original, $image->image_type);
         unset($image);
         $image = new SimpleImage();
         $image->load($file['tmp_name']);
         $image->resizeToFill($configImageWidth, $configImageHeight);
         $image->save($target_file, $image->image_type);
         //now we update the user avatar. If needed, we remove the old avatar.
         if ($oldAvatar != 'default.png') {
             if (JFile::exists($tempAvatar)) {
                 JFile::delete($tempAvatar);
             }
         }
         return JFile::makeSafe($file['name']);
     } else {
         return 'default.png';
     }
 }
开发者ID:pguilford,项目名称:vcomcc,代码行数:101,代码来源:helper.php


注:本文中的SimpleImage::resizeOriginal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。