private function saveAvatars($source, $thumbOptions, $upload = null)
{
try {
$ext = '';
if (!$upload) {
$upload = new Gdn_UploadImage();
$ext = 'jpg';
}
// Generate the target image name
$targetImage = $upload->generateTargetName(PATH_UPLOADS, $ext, true);
$imageBaseName = pathinfo($targetImage, PATHINFO_BASENAME);
$subdir = stringBeginsWith(dirname($targetImage), PATH_UPLOADS . '/', false, true);
// Save the profile size image.
$parts = Gdn_UploadImage::saveImageAs($source, self::AVATAR_FOLDER . "/{$subdir}/p{$imageBaseName}", c('Garden.Profile.MaxHeight', 1000), c('Garden.Profile.MaxWidth', 250), array('SaveGif' => c('Garden.Thumbnail.SaveGif')));
$thumbnailSize = c('Garden.Thumbnail.Size', 40);
// Save the thumbnail size image.
Gdn_UploadImage::saveImageAs($source, self::AVATAR_FOLDER . "/{$subdir}/n{$imageBaseName}", $thumbnailSize, $thumbnailSize, $thumbOptions);
} catch (Exception $ex) {
$this->Form->addError($ex);
return false;
}
$bak = $this->User->Photo;
$userPhoto = sprintf($parts['SaveFormat'], self::AVATAR_FOLDER . "/{$subdir}/{$imageBaseName}");
if (!$this->UserModel->save(array('UserID' => $this->User->UserID, 'Photo' => $userPhoto), array('CheckExisting' => true))) {
$this->Form->setValidationResults($this->UserModel->validationResults());
} else {
$this->User->Photo = $userPhoto;
}
$this->deleteAvatars($bak);
return $userPhoto;
}