本文整理汇总了PHP中Gdn_UploadImage::SaveImageAs方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_UploadImage::SaveImageAs方法的具体用法?PHP Gdn_UploadImage::SaveImageAs怎么用?PHP Gdn_UploadImage::SaveImageAs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_UploadImage
的用法示例。
在下文中一共展示了Gdn_UploadImage::SaveImageAs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processAvatars
/**
* Create different sizes of user photos.
*/
public function processAvatars()
{
$UploadImage = new Gdn_UploadImage();
$UserData = $this->SQL->select('u.Photo')->from('User u')->where('u.Photo is not null')->get();
// Make sure the avatars folder exists.
if (!file_exists(PATH_UPLOADS . '/userpics')) {
mkdir(PATH_UPLOADS . '/userpics');
}
// Get sizes
$ProfileHeight = c('Garden.Profile.MaxHeight', 1000);
$ProfileWidth = c('Garden.Profile.MaxWidth', 250);
$ThumbSize = c('Garden.Thumbnail.Size', 40);
// Temporarily set maximum quality
saveToConfig('Garden.UploadImage.Quality', 100, false);
// Create profile and thumbnail sizes
foreach ($UserData->result() as $User) {
try {
$Image = PATH_ROOT . DS . 'uploads' . DS . GetValue('Photo', $User);
$ImageBaseName = pathinfo($Image, PATHINFO_BASENAME);
// Save profile size
$UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/p' . $ImageBaseName, $ProfileHeight, $ProfileWidth);
// Save thumbnail size
$UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, true);
} catch (Exception $ex) {
}
}
}
示例2: ProcessAvatars
/**
* Create different sizes of user photos.
*/
public function ProcessAvatars()
{
$UploadImage = new Gdn_UploadImage();
$UserData = $this->SQL->Select('u.Photo')->From('User u')->Where('u.Photo is not null')->Get();
// Make sure the avatars folder exists.
if (!file_exists(PATH_UPLOADS . '/userpics')) {
mkdir(PATH_UPLOADS . '/userpics');
}
$ProfileHeight = C('Garden.Profile.MaxHeight', 1000);
$ProfileWidth = C('Garden.Profile.MaxWidth', 250);
$PreviewHeight = C('Garden.Preview.MaxHeight', 100);
$PreviewWidth = C('Garden.Preview.MaxWidth', 75);
$ThumbSize = C('Garden.Thumbnail.Size', 50);
foreach ($UserData->Result() as $User) {
try {
$Image = PATH_ROOT . DS . 'uploads' . DS . $User->Photo;
$ImageBaseName = pathinfo($Image, PATHINFO_BASENAME);
// Save profile size
$UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/p' . $ImageBaseName, $ProfileHeight, $ProfileWidth);
// Save thumbnail size
$UploadImage->SaveImageAs($Image, PATH_UPLOADS . '/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
} catch (Exception $ex) {
}
}
}
示例3: processAvatars
/**
* Create different sizes of user photos.
*/
public function processAvatars()
{
$UploadImage = new Gdn_UploadImage();
$UserData = $this->SQL->select('u.Photo')->from('User u')->get();
foreach ($UserData->result() as $User) {
try {
$Image = PATH_ROOT . DS . 'uploads' . DS . str_replace('userpics', 'attachments', $User->Photo);
// Check extension length
$ImageExtension = strlen(pathinfo($Image, PATHINFO_EXTENSION));
$ImageBaseName = pathinfo($Image, PATHINFO_BASENAME) + 1;
if (!file_exists($Image)) {
rename(substr($Image, 0, -$ImageExtension), $Image);
}
// Make sure the avatars folder exists.
if (!file_exists(PATH_ROOT . '/uploads/userpics')) {
mkdir(PATH_ROOT . '/uploads/userpics');
}
// Save the uploaded image in profile size
if (!file_exists(PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName)) {
$UploadImage->SaveImageAs($Image, PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName, Gdn::config('Garden.Profile.MaxHeight', 1000), Gdn::config('Garden.Profile.MaxWidth', 250));
}
// Save the uploaded image in preview size
/*if (!file_exists(PATH_ROOT.'/uploads/userpics/t'.$ImageBaseName))
$UploadImage->SaveImageAs(
$Image,
PATH_ROOT.'/uploads/userpics/t'.$ImageBaseName,
Gdn::config('Garden.Preview.MaxHeight', 100),
Gdn::config('Garden.Preview.MaxWidth', 75)
);*/
// Save the uploaded image in thumbnail size
$ThumbSize = Gdn::config('Garden.Thumbnail.Size', 40);
if (!file_exists(PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName)) {
$UploadImage->SaveImageAs($Image, PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, true);
}
} catch (Exception $ex) {
}
}
}
示例4: PostController_Imageupload_create
public function PostController_Imageupload_create()
{
try {
$UploadImage = new Gdn_UploadImage();
$TmpImage = $UploadImage->ValidateUpload('image_file');
// Generate the target image name.
$TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS . '/imageupload', '', TRUE);
$Props = $UploadImage->SaveImageAs($TmpImage, $TargetImage, C('Plugins.UploadImage.MaxHeight', ''), C('Plugins.UploadImage.MaxWidth', 650));
echo json_encode(array('url' => $Props['Url'], 'name' => $UploadImage->GetUploadedFileName()));
} catch (Exception $e) {
header('HTTP/1.0 400', TRUE, 400);
echo $e;
}
}
示例5: SettingsController_TouchIcon_Create
/**
* Touch icon management screen.
*
* @since 1.0
* @access public
*/
public function SettingsController_TouchIcon_Create($Sender)
{
$Sender->Permission('Garden.Settings.Manage');
$Sender->AddSideMenu('settings/touchicon');
$Sender->Title(T('Touch Icon'));
if ($Sender->Form->AuthenticatedPostBack()) {
$Upload = new Gdn_UploadImage();
try {
// Validate the upload
$TmpImage = $Upload->ValidateUpload('TouchIcon', FALSE);
if ($TmpImage) {
// Save the uploaded image.
$TouchIconPath = 'banner/touchicon_' . substr(md5(microtime()), 16) . '.png';
$ImageInfo = $Upload->SaveImageAs($TmpImage, $TouchIconPath, 114, 114, array('OutputType' => 'png', 'ImageQuality' => '8'));
SaveToConfig('Garden.TouchIcon', $ImageInfo['SaveName']);
}
} catch (Exception $ex) {
$Sender->Form->AddError($ex->getMessage());
}
$Sender->InformMessage(T("Your icon has been saved."));
}
$Sender->SetData('Path', $this->getIconUrl());
$Sender->Render($this->GetView('touchicon.php'));
}
示例6: Picture
public function Picture($UserReference = '', $Username = '')
{
$this->Permission('Garden.SignIn.Allow');
$Session = Gdn::Session();
if (!$Session->IsValid()) {
$this->Form->AddError('You must be authenticated in order to use this form.');
}
$ImageManipOk = FALSE;
if (function_exists('gd_info')) {
$GdInfo = gd_info();
$GdVersion = preg_replace('/[a-z ()]+/i', '', $GdInfo['GD Version']);
if ($GdVersion < 2) {
throw new Exception(sprintf(T("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $GdVersion));
}
} else {
throw new Exception(sprintf(T("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better.")));
}
$this->GetUserInfo($UserReference, $Username);
$this->Form->SetModel($this->UserModel);
$this->Form->AddHidden('UserID', $this->User->UserID);
if ($this->Form->AuthenticatedPostBack() === TRUE) {
$UploadImage = new Gdn_UploadImage();
try {
// Validate the upload
$TmpImage = $UploadImage->ValidateUpload('Picture');
// Generate the target image name
$TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images
@unlink(PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'p%s'));
// Don't delete this one because it hangs around in activity streams:
// @unlink(PATH_ROOT.'/uploads/'.ChangeBasename($this->User->Photo, 't%s'));
@unlink(PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'n%s'));
// Make sure the avatars folder exists.
if (!file_exists(PATH_ROOT . '/uploads/userpics')) {
mkdir(PATH_ROOT . '/uploads/userpics');
}
// Save the uploaded image in profile size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
// Save the uploaded image in preview size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/t' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
// Save the uploaded image in thumbnail size
$ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
} catch (Exception $ex) {
$this->Form->AddError($ex->getMessage());
}
// If there were no errors, associate the image with the user
if ($this->Form->ErrorCount() == 0) {
if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'Photo' => 'userpics/' . $ImageBaseName))) {
$this->Form->SetValidationResults($this->UserModel->ValidationResults());
}
}
// If there were no problems, redirect back to the user account
if ($this->Form->ErrorCount() == 0) {
Redirect('dashboard/profile/' . $UserReference);
}
}
if ($this->Form->ErrorCount() > 0) {
$this->DeliveryType(DELIVERY_TYPE_ALL);
}
$this->Render();
}
示例7: Thumbnail
public function Thumbnail($UserReference = '', $Username = '') {
$this->Permission('Garden.SignIn.Allow');
$this->AddJsFile('jquery.jcrop.pack.js');
$this->AddJsFile('profile.js');
$Session = Gdn::Session();
if (!$Session->IsValid())
$this->Form->AddError('You must be authenticated in order to use this form.');
$this->GetUserInfo($UserReference, $Username);
if ($this->User->UserID != $Session->UserID && !$Session->CheckPermission('Garden.Users.Edit'))
throw new Exception(T('You cannot edit the thumbnail of another member.'));
$this->Form->SetModel($this->UserModel);
$this->Form->AddHidden('UserID', $this->User->UserID);
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', 32);
// 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);
}
// 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,
'userpics/'.ChangeBasename(basename($this->User->Photo), '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')));
} catch (Exception $Ex) {
$this->Form->AddError($Ex);
}
// If there were no problems, redirect back to the user account
if ($this->Form->ErrorCount() == 0) {
Redirect('dashboard/profile/'.$this->ProfileUrl());
}
}
// Delete the source image if it is externally hosted.
if ($PhotoParsed['Type']) {
@unlink($Source);
}
$this->Render();
}
示例8: Banner
/**
* Banner management screen.
*
* @since 2.0.0
* @access public
*/
public function Banner()
{
$this->Permission('Garden.Settings.Manage');
$this->AddSideMenu('dashboard/settings/banner');
$this->Title(T('Banner'));
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('Garden.HomepageTitle' => C('Garden.Title'), 'Garden.Title', 'Garden.Description'));
// Set the model on the form.
$this->Form->SetModel($ConfigurationModel);
// Get the current logo.
$Logo = C('Garden.Logo');
if ($Logo) {
$Logo = ltrim($Logo, '/');
// Fix the logo path.
if (StringBeginsWith($Logo, 'uploads/')) {
$Logo = substr($Logo, strlen('uploads/'));
}
$this->SetData('Logo', $Logo);
}
// Get the current favicon.
$Favicon = C('Garden.FavIcon');
$this->SetData('Favicon', $Favicon);
$ShareImage = C('Garden.ShareImage');
$this->SetData('ShareImage', $ShareImage);
// If seeing the form for the first time...
if (!$this->Form->AuthenticatedPostBack()) {
// Apply the config settings to the form.
$this->Form->SetData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
$SaveData = array();
if ($this->Form->Save() !== FALSE) {
$Upload = new Gdn_Upload();
try {
// Validate the upload
$TmpImage = $Upload->ValidateUpload('Logo', FALSE);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images.
if ($Logo) {
$Upload->Delete($Logo);
}
// Save the uploaded image
$Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
$ImageBaseName = $Parts['SaveName'];
$SaveData['Garden.Logo'] = $ImageBaseName;
$this->SetData('Logo', $ImageBaseName);
}
$ImgUpload = new Gdn_UploadImage();
$TmpFavicon = $ImgUpload->ValidateUpload('Favicon', FALSE);
if ($TmpFavicon) {
$ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
if ($Favicon) {
$Upload->Delete($Favicon);
}
// Resize the to a png.
$Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => TRUE));
$SaveData['Garden.FavIcon'] = $Parts['SaveName'];
$this->SetData('Favicon', $Parts['SaveName']);
}
$TmpShareImage = $Upload->ValidateUpload('ShareImage', FALSE);
if ($TmpShareImage) {
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, FALSE);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
if ($ShareImage) {
$Upload->Delete($ShareImage);
}
$Parts = $Upload->SaveAs($TmpShareImage, $ImageBaseName);
$SaveData['Garden.ShareImage'] = $Parts['SaveName'];
$this->SetData('ShareImage', $Parts['SaveName']);
}
} catch (Exception $ex) {
$this->Form->AddError($ex);
}
// If there were no errors, save the path to the logo in the config
if ($this->Form->ErrorCount() == 0) {
SaveToConfig($SaveData);
}
$this->InformMessage(T("Your settings have been saved."));
}
}
$this->Render();
}
示例9: Picture
public function Picture($UserReference = '')
{
$this->Permission('Garden.SignIn.Allow');
$Session = Gdn::Session();
if (!$Session->IsValid()) {
$this->Form->AddError('You must be authenticated in order to use this form.');
}
$this->GetUserInfo($UserReference);
$this->Form->SetModel($this->UserModel);
$this->Form->AddHidden('UserID', $this->User->UserID);
if ($this->Form->AuthenticatedPostBack() === TRUE) {
$UploadImage = new Gdn_UploadImage();
try {
// Validate the upload
$TmpImage = $UploadImage->ValidateUpload('Picture');
// Generate the target image name
$TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image in large size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'o' . $ImageBaseName, Gdn::Config('Garden.Picture.MaxHeight', 1000), Gdn::Config('Garden.Picture.MaxWidth', 1000));
// Save the uploaded image in profile size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
// Save the uploaded image in preview size
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
// Save the uploaded image in thumbnail size
$ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
$UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
} catch (Exception $ex) {
$this->Form->AddError($ex->getMessage());
}
// If there were no errors, associate the image with the user
if ($this->Form->ErrorCount() == 0) {
$PhotoModel = new Model('Photo');
$PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
$this->Form->SetValidationResults($this->UserModel->ValidationResults());
}
}
// If there were no problems, redirect back to the user account
if ($this->Form->ErrorCount() == 0) {
Redirect('garden/profile/' . $UserReference);
}
}
$this->Render();
}
示例10: 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();
}
示例11: ThumbnailImage
function ThumbnailImage($Data, $Attributes = False)
{
if (function_exists('Debug') && Debug()) {
Deprecated(__FUNCTION__, 'Thumbnail');
}
$Width = ArrayValue('width', $Attributes, '');
$Height = ArrayValue('height', $Attributes, '');
if (Is_Array($Data)) {
// group, todo
// <ul><li><a></a></li>
}
$Prefix = substr($Data, 0, 7);
//if(In_Array($Prefix, array('http://', 'https:/'))) {}
//$bLocalImage = False;
if ($Prefix != 'http://') {
//$bLocalImage = True;
$IncomingImage = $Data;
$ImageFindPaths[] = 'uploads' . DS . $Data;
$ImageFindPaths[] = $Data;
foreach ($ImageFindPaths as $File) {
if (file_exists($File) && is_file($File)) {
$IncomingImage = $File;
break;
}
}
} else {
$IncomingImage = $Data;
}
$CacheDirectory = 'uploads/cached';
if (!is_writable($CacheDirectory)) {
mkdir($CacheDirectory, 0777, True);
if (!is_writable($CacheDirectory)) {
$ErrorMessage = ErrorMessage(sprintf(T('Directory (%s) is not writable.'), $CacheDirectory), 'PHP', __FUNCTION__);
trigger_error($ErrorMessage, E_USER_ERROR);
return '';
}
}
$Name = CleanupString(pathinfo($IncomingImage, PATHINFO_FILENAME) . ' ' . $Width . ' ' . $Height);
$Extension = FileExtension($IncomingImage);
$Target = $CacheDirectory . DS . $Name . '.' . $Extension;
if (!file_exists($Target)) {
Gdn_UploadImage::SaveImageAs($IncomingImage, $Target, $Height, $Width);
}
$Target = str_replace(DS, '/', $Target);
if (!array_key_exists('alt', $Attributes)) {
$Attributes['alt'] = pathinfo($Name, PATHINFO_FILENAME);
}
list($Width, $Height, $Type) = GetImageSize($IncomingImage);
$Attributes['alt'] .= sprintf(' (%d×%d)', $Width, $Height);
$Image = Img($Target, $Attributes);
return Anchor($Image, Url($IncomingImage), '', '', True);
}
示例12: banner
/**
* Banner management screen.
*
* @since 2.0.0
* @access public
*/
public function banner()
{
$this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
$this->setHighlightRoute('dashboard/settings/banner');
$this->title(t('Banner'));
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->setField(array('Garden.HomepageTitle' => c('Garden.Title'), 'Garden.Title', 'Garden.Description'));
// Set the model on the form.
$this->Form->setModel($ConfigurationModel);
// Get the current logo.
$Logo = c('Garden.Logo');
if ($Logo) {
$Logo = ltrim($Logo, '/');
// Fix the logo path.
if (stringBeginsWith($Logo, 'uploads/')) {
$Logo = substr($Logo, strlen('uploads/'));
}
$this->setData('Logo', $Logo);
}
// Get the current mobile logo.
$MobileLogo = c('Garden.MobileLogo');
if ($MobileLogo) {
$MobileLogo = ltrim($MobileLogo, '/');
// Fix the logo path.
if (stringBeginsWith($MobileLogo, 'uploads/')) {
$MobileLogo = substr($MobileLogo, strlen('uploads/'));
}
$this->setData('MobileLogo', $MobileLogo);
}
// Get the current favicon.
$Favicon = c('Garden.FavIcon');
$this->setData('Favicon', $Favicon);
$ShareImage = c('Garden.ShareImage');
$this->setData('ShareImage', $ShareImage);
// If seeing the form for the first time...
if (!$this->Form->authenticatedPostBack()) {
// Apply the config settings to the form.
$this->Form->setData($ConfigurationModel->Data);
} else {
$SaveData = array();
if ($this->Form->save() !== false) {
$Upload = new Gdn_Upload();
try {
// Validate the upload
$TmpImage = $Upload->validateUpload('Logo', false);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images.
if ($Logo) {
$Upload->delete($Logo);
}
// Save the uploaded image
$Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
$ImageBaseName = $Parts['SaveName'];
$SaveData['Garden.Logo'] = $ImageBaseName;
$this->setData('Logo', $ImageBaseName);
}
$TmpMobileImage = $Upload->validateUpload('MobileLogo', false);
if ($TmpMobileImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images.
if ($MobileLogo) {
$Upload->delete($MobileLogo);
}
// Save the uploaded image
$Parts = $Upload->saveAs($TmpMobileImage, $ImageBaseName);
$ImageBaseName = $Parts['SaveName'];
$SaveData['Garden.MobileLogo'] = $ImageBaseName;
$this->setData('MobileLogo', $ImageBaseName);
}
$ImgUpload = new Gdn_UploadImage();
$TmpFavicon = $ImgUpload->validateUpload('Favicon', false);
if ($TmpFavicon) {
$ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
if ($Favicon) {
$Upload->delete($Favicon);
}
// Resize the to a png.
$Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => true));
$SaveData['Garden.FavIcon'] = $Parts['SaveName'];
$this->setData('Favicon', $Parts['SaveName']);
}
$TmpShareImage = $Upload->ValidateUpload('ShareImage', false);
if ($TmpShareImage) {
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, false);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
if ($ShareImage) {
$Upload->delete($ShareImage);
}
//.........这里部分代码省略.........
示例13: FancyZoomImage
function FancyZoomImage($Source, $Attributes = array())
{
// defaults
if (!is_array($Attributes)) {
$Attributes = array();
}
$NoHiding = GetValue('NoHiding', $Attributes, '', True);
$bSaveImage = False;
$Hash = Crc32Value($Source, $Attributes);
$Filename = pathinfo($Source, PATHINFO_FILENAME);
$Extension = pathinfo($Source, PATHINFO_EXTENSION);
if (!array_key_exists('SmallImage', $Attributes)) {
// make directory
$TargetFolder = 'uploads/cached';
// cache directory
if (!is_dir($TargetFolder)) {
mkdir($TargetFolder, 0777, True);
}
$SmallImage = GenerateCleanTargetName($TargetFolder, $Filename . '-' . $Hash, $Extension, False, True);
$Attributes['SmallImage'] = $SmallImage;
if (!file_exists($SmallImage)) {
$bSaveImage = True;
}
}
// get attributes
$Width = ArrayValue('width', $Attributes, '');
$Height = ArrayValue('height', $Attributes, '');
$Crop = GetValue('Crop', $Attributes, False, True);
$SmallImage = GetValue('SmallImage', $Attributes, '', True);
$ZoomAttributes = array('id' => 'p' . $Hash);
if (!$NoHiding) {
$ZoomAttributes['style'] = 'display:none';
}
//if (!array_key_exists('alt', $Attributes)) $Attributes['alt'] = $Filename;
TouchValue('alt', $Attributes, $Filename);
if ($bSaveImage) {
Gdn_UploadImage::SaveImageAs($Source, $SmallImage, $Height, $Width, $Crop);
}
$SmallImage = Img($SmallImage, $Attributes);
$ZoomImage = Img($Source, array('alt' => ArrayValue('alt', $Attributes, '')));
return "\n" . Wrap($SmallImage, 'a', array('href' => '#p' . $Hash)) . Wrap($ZoomImage, 'div', $ZoomAttributes);
}
示例14: SaveImage
/**
* Save an image from a field and delete any old image that's been uploaded.
*
* @param string $Field The name of the field. The image will be uploaded with the _New extension while the current image will be just the field name.
* @param array $Options
*/
public function SaveImage($Field, $Options = array())
{
$Upload = new Gdn_UploadImage();
$FileField = str_replace('.', '_', $Field);
if (!GetValueR("{$FileField}_New.name", $_FILES)) {
Trace("{$Field} not uploaded, returning.");
return FALSE;
}
// First make sure the file is valid.
try {
$TmpName = $Upload->ValidateUpload($FileField . '_New', TRUE);
if (!$TmpName) {
return FALSE;
}
// no file uploaded.
} catch (Exception $Ex) {
$this->AddError($Ex);
return FALSE;
}
// Get the file extension of the file.
$Ext = GetValue('OutputType', $Options, trim($Upload->GetUploadedFileExtension(), '.'));
if ($Ext == 'jpeg') {
$Ext = 'jpg';
}
Trace($Ext, 'Ext');
// The file is valid so let's come up with its new name.
if (isset($Options['Name'])) {
$Name = $Options['Name'];
} elseif (isset($Options['Prefix'])) {
$Name = $Options['Prefix'] . md5(microtime()) . '.' . $Ext;
} else {
$Name = md5(microtime()) . '.' . $Ext;
}
// We need to parse out the size.
$Size = GetValue('Size', $Options);
if ($Size) {
if (is_numeric($Size)) {
TouchValue('Width', $Options, $Size);
TouchValue('Height', $Options, $Size);
} elseif (preg_match('`(\\d+)x(\\d+)`i', $Size, $M)) {
TouchValue('Width', $Options, $M[1]);
TouchValue('Height', $Options, $M[2]);
}
}
Trace($Options, "Saving image {$Name}.");
try {
$Parsed = $Upload->SaveImageAs($TmpName, $Name, GetValue('Height', $Options, ''), GetValue('Width', $Options, ''), $Options);
Trace($Parsed, 'Saved Image');
$Current = $this->GetFormValue($Field);
if ($Current && GetValue('DeleteOriginal', $Options, TRUE)) {
// Delete the current image.
Trace("Deleting original image: {$Current}.");
if ($Current) {
$Upload->Delete($Current);
}
}
// Set the current value.
$this->SetFormValue($Field, $Parsed['SaveName']);
} catch (Exception $Ex) {
$this->AddError($Ex);
}
}
示例15: UtilityController_Thumbnail_Create
public function UtilityController_Thumbnail_Create($Sender, $Args)
{
$SubPath = implode('/', $Args);
$Path = MediaModel::PathUploads() . "/{$SubPath}";
if (!file_exists($Path)) {
throw NotFoundException('File');
}
// Figure out the dimensions of the upload.
$ImageSize = getimagesize($Path);
$SHeight = $ImageSize[1];
$SWidth = $ImageSize[0];
$Options = array();
$ThumbHeight = MediaModel::ThumbnailHeight();
$ThumbWidth = MediaModel::ThumbnailWidth();
if (!$ThumbHeight || $SHeight < $ThumbHeight) {
$Height = $SHeight;
$Width = $SWidth;
} else {
$Height = $ThumbHeight;
$Width = round($Height * $SWidth / $SHeight);
}
if ($ThumbWidth && $Width > $ThumbWidth) {
$Width = $ThumbWidth;
if (!$ThumbHeight) {
$Height = round($Width * $SHeight / $SWidth);
} else {
$Options['Crop'] = TRUE;
}
}
$TargetPath = MediaModel::PathUploads() . "/thumbnails/{$SubPath}";
if (!file_exists(dirname($TargetPath))) {
mkdir(dirname($TargetPath), 0777, TRUE);
}
Gdn_UploadImage::SaveImageAs($Path, $TargetPath, $Height, $Width, $Options);
$Url = MediaModel::Url("/thumbnails/{$SubPath}");
Redirect($Url, 302);
// Gdn_FileSystem::ServeFile($TargetPath, basename($Path), '', 'inline');
}