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


PHP Gdn_UploadImage::SaveAs方法代码示例

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


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

示例1: Thumbnail

 /**
  * Set user's thumbnail (crop & center photo).
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possible username or ID.
  * @param string $Username.
  */
 public function Thumbnail($UserReference = '', $Username = '')
 {
     if (!C('Garden.Profile.EditPhotos', TRUE)) {
         throw ForbiddenException('@Editing user photos has been disabled.');
     }
     // Initial permission checks (valid user)
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     // Need some extra JS
     // jcrop update jan28, 2014 as jQuery upgrade to 1.10.2 no longer
     // supported browser()
     $this->AddJsFile('jquery.jcrop.min.js');
     $this->AddJsFile('profile.js');
     $this->GetUserInfo($UserReference, $Username, '', TRUE);
     // Permission check (correct user)
     if ($this->User->UserID != $Session->UserID && !CheckPermission('Garden.Users.Edit') && !CheckPermission('Moderation.Profiles.Edit')) {
         throw new Exception(T('You cannot edit the thumbnail of another member.'));
     }
     // Form prep
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     // Confirm we have a photo to manipulate
     if (!$this->User->Photo) {
         $this->Form->AddError('You must first upload a picture before you can create a thumbnail.');
     }
     // Define the thumbnail size
     $this->ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 40);
     // Define the source (profile sized) picture & dimensions.
     $Basename = ChangeBasename($this->User->Photo, 'p%s');
     $Upload = new Gdn_UploadImage();
     $PhotoParsed = Gdn_Upload::Parse($Basename);
     $Source = $Upload->CopyLocal($Basename);
     if (!$Source) {
         $this->Form->AddError('You cannot edit the thumbnail of an externally linked profile picture.');
     } else {
         $this->SourceSize = getimagesize($Source);
     }
     // We actually need to upload a new file to help with cdb ttls.
     $NewPhoto = $Upload->GenerateTargetName('userpics', trim(pathinfo($this->User->Photo, PATHINFO_EXTENSION), '.'), TRUE);
     // Add some more hidden form fields for jcrop
     $this->Form->AddHidden('x', '0');
     $this->Form->AddHidden('y', '0');
     $this->Form->AddHidden('w', $this->ThumbSize);
     $this->Form->AddHidden('h', $this->ThumbSize);
     $this->Form->AddHidden('HeightSource', $this->SourceSize[1]);
     $this->Form->AddHidden('WidthSource', $this->SourceSize[0]);
     $this->Form->AddHidden('ThumbSize', $this->ThumbSize);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         try {
             // Get the dimensions from the form.
             Gdn_UploadImage::SaveImageAs($Source, ChangeBasename($NewPhoto, 'n%s'), $this->ThumbSize, $this->ThumbSize, array('Crop' => TRUE, 'SourceX' => $this->Form->GetValue('x'), 'SourceY' => $this->Form->GetValue('y'), 'SourceWidth' => $this->Form->GetValue('w'), 'SourceHeight' => $this->Form->GetValue('h')));
             // Save new profile picture.
             $Parsed = $Upload->SaveAs($Source, ChangeBasename($NewPhoto, 'p%s'));
             $UserPhoto = sprintf($Parsed['SaveFormat'], $NewPhoto);
             // Save the new photo info.
             Gdn::UserModel()->SetField($this->User->UserID, 'Photo', $UserPhoto);
             // Remove the old profile picture.
             @$Upload->Delete($Basename);
         } catch (Exception $Ex) {
             $this->Form->AddError($Ex);
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect(UserUrl($this->User, '', 'picture'));
             $this->InformMessage(Sprite('Check', 'InformSprite') . T('Your changes have been saved.'), 'Dismissable AutoDismiss HasSprite');
         }
     }
     // Delete the source image if it is externally hosted.
     if ($PhotoParsed['Type']) {
         @unlink($Source);
     }
     $this->Title(T('Edit My Thumbnail'));
     $this->_SetBreadcrumbs(T('Edit My Thumbnail'), '/profile/thumbnail');
     $this->Render();
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:86,代码来源:class.profilecontroller.php


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