image cropping
This commit is contained in:
parent
137ef0721f
commit
ac70ea60e3
|
@ -1744,24 +1744,70 @@ class windowsUser extends baseModule implements passwordService {
|
||||||
*
|
*
|
||||||
* @return array meta HTML code
|
* @return array meta HTML code
|
||||||
*/
|
*/
|
||||||
function display_html_photo() {
|
public function display_html_photo() {
|
||||||
$container = new htmlTable();
|
$container = new htmlTable();
|
||||||
|
if (empty($this->attributes['jpegPhoto'][0])) {
|
||||||
|
$container->addElement(new htmlSubTitle(_('Upload image')), true);
|
||||||
$label = _('Photo file');
|
$label = _('Photo file');
|
||||||
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
|
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
|
||||||
|
$container->addVerticalSpace('1rem');
|
||||||
$buttonContainer = new htmlTable();
|
$buttonContainer = new htmlTable();
|
||||||
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo')));
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'photo', 'upload', _('Upload')));
|
||||||
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')));
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')));
|
||||||
$container->addElement($buttonContainer);
|
$container->addElement($buttonContainer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$container->addElement(new htmlSubTitle(_('Crop image')), true);
|
||||||
|
$jpeg_filename = 'jpg' . getRandomNumber() . '.jpg';
|
||||||
|
$outjpeg = @fopen(dirname(__FILE__) . '/../../tmp/' . $jpeg_filename, "wb");
|
||||||
|
fwrite($outjpeg, $this->attributes['jpegPhoto'][0]);
|
||||||
|
fclose ($outjpeg);
|
||||||
|
$photoFile = '../../tmp/' . $jpeg_filename;
|
||||||
|
$img = new htmlImage($photoFile);
|
||||||
|
$img->setCSSClasses(array('photo'));
|
||||||
|
$img->enableCropping();
|
||||||
|
$container->addElement($img, true);
|
||||||
|
$container->addVerticalSpace('1rem');
|
||||||
|
$buttonContainer = new htmlTable();
|
||||||
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'crop', _('Done')));
|
||||||
|
$container->addElement($buttonContainer, true);
|
||||||
|
}
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a new photo.
|
* Sets a new photo.
|
||||||
*/
|
*/
|
||||||
function process_photo() {
|
public function process_photo() {
|
||||||
if (!isset($_POST['form_subpage_' . get_class($this) . '_attributes_submit'])) {
|
if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_back'])) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
if (isset($_POST['form_subpage_' . get_class($this) . '_photo_upload'])) {
|
||||||
|
return $this->uploadPhoto();
|
||||||
|
}
|
||||||
|
if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_crop'])) {
|
||||||
|
$messages = array();
|
||||||
|
$image = new Imagick();
|
||||||
|
try {
|
||||||
|
$image->readImageBlob($this->attributes['jpegPhoto'][0]);
|
||||||
|
$image->cropimage($_POST['croppingDataWidth'], $_POST['croppingDataHeight'], $_POST['croppingDataX'], $_POST['croppingDataY']);
|
||||||
|
$this->attributes['jpegPhoto'][0] = $image->getimageblob();
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$msg = $this->messages['file'][2];
|
||||||
|
$msg[] = htmlspecialchars($e->getMessage());
|
||||||
|
$messages[] = $msg;
|
||||||
|
}
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads the photo file.
|
||||||
|
*
|
||||||
|
* @return array error messages if any
|
||||||
|
*/
|
||||||
|
private function uploadPhoto() {
|
||||||
$messages = array();
|
$messages = array();
|
||||||
if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) {
|
if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) {
|
||||||
$name = $_FILES['photoFile']['name'];
|
$name = $_FILES['photoFile']['name'];
|
||||||
|
@ -1775,7 +1821,7 @@ class windowsUser extends baseModule implements passwordService {
|
||||||
return array($errMsg);
|
return array($errMsg);
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
// convert to JPG if imagick extension is available
|
// convert to JPG
|
||||||
$image = new Imagick();
|
$image = new Imagick();
|
||||||
try {
|
try {
|
||||||
$image->readImageBlob($data);
|
$image->readImageBlob($data);
|
||||||
|
|
Loading…
Reference in New Issue