From 8358172e8b517a12d04b57d397b3bc95234ee429 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 1 Nov 2013 14:14:47 +0000 Subject: [PATCH] auto-convert photos to JPG (158) --- lam/HISTORY | 2 ++ lam/lib/modules/inetOrgPerson.inc | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lam/HISTORY b/lam/HISTORY index 237cfefd..34900bfe 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -6,6 +6,8 @@ December 2013 4.4 -> Bind DLZ support -> Samba/Shadow: display password change date in self service -> Custom fields: support custom label and icon, auto-completion + - fixed bugs: + -> Format of photo in Personal tab (158) 25.09.2013 4.3 diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index e43e49cb..3111850a 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -94,6 +94,8 @@ class inetOrgPerson extends baseModule implements passwordService { $this->messages['uid'][3] = array('ERROR', _('Account %s:') . ' inetOrgPerson_userName', _('User name already exists!')); $this->messages['manager'][0] = array('ERROR', _('Account %s:') . ' inetOrgPerson_manager', _('This is not a valid DN!')); $this->messages['file'][0] = array('ERROR', _('No file selected.')); + $this->messages['file'][1] = array('ERROR', _('Please upload a .jpg/.jpeg file.')); + $this->messages['file'][2] = array('ERROR', _('Unable to process this file.')); $this->messages['businessCategory'][0] = array('ERROR', _('Business category'), _('Please enter a valid business category!')); $this->messages['businessCategory'][1] = array('ERROR', _('Account %s:') . ' inetOrgPerson_businessCategory', _('Please enter a valid business category!')); $this->messages['userPassword'][0] = array('ERROR', _('Account %s:') . ' posixAccount_password', _('Password contains invalid characters. Valid characters are:') . ' a-z, A-Z, 0-9 and #*,.;:_-+!%&/|?{[()]}=@$ §°!'); @@ -2121,9 +2123,31 @@ class inetOrgPerson extends baseModule implements passwordService { } $messages = array(); if ($_FILES['photoFile'] && ($_FILES['photoFile']['size'] > 0)) { + $name = $_FILES['photoFile']['name']; + $extension = strtolower(substr($name, strpos($name, '.') + 1)); + if (!extension_loaded('imagick') && !($extension == '.jpg') && !($extension == '.jpeg')) { + $messages[] = $this->messages['file'][1]; + return $messages; + } $handle = fopen($_FILES['photoFile']['tmp_name'], "r"); - $data = fread($handle, 1000000); + $data = fread($handle, 10000000); fclose($handle); + if (extension_loaded('imagick')) { + // convert to JPG if imagick extension is available + $image = new Imagick(); + try { + $image->readImageBlob($data); + $image->setImageCompression(Imagick::COMPRESSION_JPEG); + $image->setImageFormat('jpeg'); + $data = $image->getimageblob(); + } + catch (Exception $e) { + $msg = $this->messages['file'][2]; + $msg[] = htmlspecialchars($e->getMessage()); + $messages[] = $msg; + return $messages; + } + } $this->attributes['jpegPhoto'][0] = $data; } else {