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
|
||||
*/
|
||||
function display_html_photo() {
|
||||
public function display_html_photo() {
|
||||
$container = new htmlTable();
|
||||
$label = _('Photo file');
|
||||
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
|
||||
$buttonContainer = new htmlTable();
|
||||
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'submit', _('Add photo')));
|
||||
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'back', _('Back')));
|
||||
$container->addElement($buttonContainer);
|
||||
if (empty($this->attributes['jpegPhoto'][0])) {
|
||||
$container->addElement(new htmlSubTitle(_('Upload image')), true);
|
||||
$label = _('Photo file');
|
||||
$container->addElement(new htmlTableExtendedInputFileUpload('photoFile', $label, 'photoUpload'), true);
|
||||
$container->addVerticalSpace('1rem');
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new photo.
|
||||
*/
|
||||
function process_photo() {
|
||||
if (!isset($_POST['form_subpage_' . get_class($this) . '_attributes_submit'])) {
|
||||
public function process_photo() {
|
||||
if (isset($_POST['form_subpage_' . get_class($this) . '_attributes_back'])) {
|
||||
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();
|
||||
if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) {
|
||||
$name = $_FILES['photoFile']['name'];
|
||||
|
@ -1775,19 +1821,19 @@ class windowsUser extends baseModule implements passwordService {
|
|||
return array($errMsg);
|
||||
}
|
||||
fclose($handle);
|
||||
// convert to JPG if imagick extension is available
|
||||
// convert to JPG
|
||||
$image = new Imagick();
|
||||
try {
|
||||
$image->readImageBlob($data);
|
||||
// resize if maximum values specified
|
||||
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];
|
||||
$maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0];
|
||||
$image->thumbnailimage($maxWidth, $maxHeight, true);
|
||||
}
|
||||
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
||||
$image->setImageFormat('jpeg');
|
||||
$data = $image->getimageblob();
|
||||
$image->readImageBlob($data);
|
||||
// resize if maximum values specified
|
||||
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];
|
||||
$maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $image->getimageheight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0];
|
||||
$image->thumbnailimage($maxWidth, $maxHeight, true);
|
||||
}
|
||||
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
|
||||
$image->setImageFormat('jpeg');
|
||||
$data = $image->getimageblob();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$msg = $this->messages['file'][2];
|
||||
|
|
Loading…
Reference in New Issue