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();
|
||||||
$label = _('Photo file');
|
if (empty($this->attributes['jpegPhoto'][0])) {
|
||||||
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
|
$container->addElement(new htmlSubTitle(_('Upload image')), true);
|
||||||
$buttonContainer = new htmlTable();
|
$label = _('Photo file');
|
||||||
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo')));
|
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
|
||||||
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')));
|
$container->addVerticalSpace('1rem');
|
||||||
$container->addElement($buttonContainer);
|
$buttonContainer = new htmlTable();
|
||||||
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'photo', 'upload', _('Upload')));
|
||||||
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')));
|
||||||
|
$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,19 +1821,19 @@ 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);
|
||||||
// resize if maximum values specified
|
// resize if maximum values specified
|
||||||
if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0])) {
|
if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0])) {
|
||||||
$maxWidth = empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0];
|
$maxWidth = empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) ? $image->getimagewidth() : $this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0];
|
||||||
$maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0];
|
$maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0];
|
||||||
$image->thumbnailimage($maxWidth, $maxHeight, true);
|
$image->thumbnailimage($maxWidth, $maxHeight, true);
|
||||||
}
|
}
|
||||||
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
||||||
$image->setImageFormat('jpeg');
|
$image->setImageFormat('jpeg');
|
||||||
$data = $image->getimageblob();
|
$data = $image->getimageblob();
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
$msg = $this->messages['file'][2];
|
$msg = $this->messages['file'][2];
|
||||||
|
|
Loading…
Reference in New Issue