From cf2b972b1de65abdfe557dc84dbacd8a16cce523 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 13 Sep 2010 07:10:22 +0000 Subject: [PATCH] Updated image rendering for user pictures git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19609 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../plugins/personal/generic/class_user.inc | 100 +++++++----------- .../plugins/personal/generic/generic.tpl | 2 +- .../personal/generic/generic_picture.tpl | 5 +- 3 files changed, 44 insertions(+), 63 deletions(-) diff --git a/gosa-core/plugins/personal/generic/class_user.inc b/gosa-core/plugins/personal/generic/class_user.inc index 3062a9a08..c677268d0 100644 --- a/gosa-core/plugins/personal/generic/class_user.inc +++ b/gosa-core/plugins/personal/generic/class_user.inc @@ -1005,69 +1005,51 @@ class user extends plugin } else { - /* Fallback if there's no image magick inside PHP */ - if (function_exists("imagick_blob2image")){ - - /* Load the new uploaded Photo */ - if(!$handle = imagick_blob2image($this->photoData)) { - new log("debug","users/".get_class($this),$this->dn,array(),"Could not access uploaded image"); - } - - /* Resizing image to 147x200 and blur */ - if(!imagick_resize($handle,147,200,IMAGICK_FILTER_GAUSSIAN,0)){ - new log("debug","users/".get_class($this),$this->dn,array(),"Could not resize uploaded image"); - } - - /* Converting image to JPEG */ - if(!imagick_convert($handle,"JPEG")) { - new log("debug","users/".get_class($this),$this->dn,array(),"Could not convert uploaded image to jepg"); - } + if(class_exists('Imagick')){ + + $im = new Imagick(); + $im->readImageBlob($this->photoData); + $im->setImageOpacity(1.0); + $im->resizeImage(147,200,Imagick::FILTER_UNDEFINED,0.5,TRUE); + $im->setCompressionQuality(90); + $im->setImageFormat('jpeg'); + $this->attrs["jpegPhoto"] = $im->getImageBlob(); + + }elseif (exec('convert')){ + /* Get temporary file name for conversation */ + $fname = tempnam (TEMP_DIR, "GOsa"); + + /* Open file and write out photoData */ + $fp = fopen ($fname, "w"); + fwrite ($fp, $this->photoData); + fclose ($fp); + + /* Build conversation query. Filename is generated automatically, so + we do not need any special security checks. Exec command and save + output. For PHP safe mode, you'll need a configuration which respects + image magick as executable... */ + $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -"; + @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, + $query, "Execute"); + + /* Read data written by convert */ + $output= ""; + $sh= popen($query, 'r'); + while (!feof($sh)){ + $output.= fread($sh, 4096); + } + pclose($sh); - /* Creating binary Code for the Image */ - if(!$dump = imagick_image2blob($handle)){ - new log("debug","users/".get_class($this),$this->dn,array(),"Could not create new user image"); - } + unlink($fname); - /* Sending Image */ - $output= $dump; + /* Save attribute */ + $this->attrs["jpegPhoto"] = $output; + }else{ + msg_dialog::display(_("Error"), + _("Cannot save user picture, GOsa requires the package 'imagemagick' or 'php5-imagick' to be installed!"), + ERROR_DIALOG); - /* Save attribute */ - $this->attrs["jpegPhoto"] = $output; - }elseif (exec('convert')){ - /* Get temporary file name for conversation */ - $fname = tempnam (TEMP_DIR, "GOsa"); - - /* Open file and write out photoData */ - $fp = fopen ($fname, "w"); - fwrite ($fp, $this->photoData); - fclose ($fp); - - /* Build conversation query. Filename is generated automatically, so - we do not need any special security checks. Exec command and save - output. For PHP safe mode, you'll need a configuration which respects - image magick as executable... */ - $query= "convert -size 147x200 $fname -resize 147x200 +profile \"*\" -"; - @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, - $query, "Execute"); - - /* Read data written by convert */ - $output= ""; - $sh= popen($query, 'r'); - while (!feof($sh)){ - $output.= fread($sh, 4096); } - pclose($sh); - - unlink($fname); - - /* Save attribute */ - $this->attrs["jpegPhoto"] = $output; - }else{ - msg_dialog::display(_("Error"), - _("Cannot save user picture, GOsa requires the package 'imagemagick' or 'php5-imagick' to be installed!"), - ERROR_DIALOG); - - } } /* Save data. Using 'modify' implies that the entry is already present, use 'add' for diff --git a/gosa-core/plugins/personal/generic/generic.tpl b/gosa-core/plugins/personal/generic/generic.tpl index 56f2dbef4..fffdffd03 100644 --- a/gosa-core/plugins/personal/generic/generic.tpl +++ b/gosa-core/plugins/personal/generic/generic.tpl @@ -14,7 +14,7 @@ {if !$userPicture_is_readable} {else} - + {/if} diff --git a/gosa-core/plugins/personal/generic/generic_picture.tpl b/gosa-core/plugins/personal/generic/generic_picture.tpl index a78630dab..0fcea1931 100644 --- a/gosa-core/plugins/personal/generic/generic_picture.tpl +++ b/gosa-core/plugins/personal/generic/generic_picture.tpl @@ -1,9 +1,8 @@

{t}User picture{/t}

-
- - + +
-- 2.30.2