require_once INSTALLDIR.'/lib/accountsettingsaction.php';
+define('MAX_ORIGINAL', 480);
+
/**
* Upload an avatar
*
var $mode = null;
var $imagefile = null;
var $filename = null;
+ var $msg = null;
+ var $success = null;
/**
* Prepare to run
}
}
- function showForm($msg = null)
+ function showForm($msg = null, $success = false)
{
- $this->msg = $msg;
+ $this->msg = $msg;
+ $this->success = $success;
+
$this->showPage();
}
'type' => 'hidden',
'id' => $crop_info));
}
+
$this->submit('crop', _('Crop'));
$this->elementEnd('li');
}
if ($this->arg('upload')) {
- $this->uploadAvatar();
+ $this->uploadLogo();
} else if ($this->arg('crop')) {
- $this->cropAvatar();
+ $this->cropLogo();
} else {
$this->showForm(_('Unexpected form submission.'));
}
* @return void
*/
- function uploadAvatar()
+ function uploadLogo()
{
try {
$imagefile = ImageFile::fromUpload('avatarfile');
* @return void
*/
- function cropAvatar()
+ function cropLogo()
{
$user = common_current_user();
return;
}
- common_debug("W = $w, H = $h, X = $x, Y = $y");
+ $size = ($w > MAX_ORIGINAL) ? MAX_ORIGINAL : $w;
- $image_dest = imagecreatetruecolor($w, $h);
+ $image_dest = imagecreatetruecolor($size, $size);
$background = imagecolorallocate($image_dest, 0, 0, 0);
ImageColorTransparent($image_dest, $background);
imagealphablending($image_dest, false);
- imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $w, $h, $w, $h);
-
- $cur = common_current_user();
+ imagecopyresized($image_dest, $image_src,
+ 0, 0, $x, $y,
+ $size, $size, $w, $h);
$filename = common_avatar_filename($this->group->id,
- image_type_to_extension($imagefile->type),
+ image_type_to_extension($filedata['type']),
null,
'group-'.common_timestamp());
{
parent::showScripts();
- $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js');
- $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js');
+ if ($this->mode == 'crop') {
+ $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js');
+ $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js');
- $this->element('script', array('type' => 'text/javascript',
- 'src' => $jcropPack));
- $this->element('script', array('type' => 'text/javascript',
- 'src' => $jcropGo));
+ $this->element('script', array('type' => 'text/javascript',
+ 'src' => $jcropPack));
+ $this->element('script', array('type' => 'text/javascript',
+ 'src' => $jcropGo));
+ }
}
function showLocalNav()