mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:15 +01:00
* scaling now addressbook images uploaded via CardDAV or SyncML to 60 pixel width like already done for web GUI
This commit is contained in:
parent
9ab9397af7
commit
14621383d6
@ -797,6 +797,11 @@ class addressbook_bo extends addressbook_so
|
||||
$this->error = 'access denied';
|
||||
return false;
|
||||
}
|
||||
// resize image to 60px width
|
||||
if (!empty($contact['jpegphoto']))
|
||||
{
|
||||
// $contact['jpegphoto'] = $this->resize_photo($contact['jpegphoto']);
|
||||
}
|
||||
// convert categories
|
||||
if (is_array($contact['cat_id']))
|
||||
{
|
||||
@ -894,6 +899,48 @@ class addressbook_bo extends addressbook_so
|
||||
return $this->error ? false : $contact['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes photo to 60*80 pixel and returns it
|
||||
*
|
||||
* @param string|FILE $photo string with image or open filedescribtor
|
||||
* @param int $dst_w=60 max width to resize to
|
||||
* @return string with resized jpeg photo, null on error
|
||||
*/
|
||||
public static function resize_photo($photo,$dst_w=60)
|
||||
{
|
||||
if (is_resource($photo))
|
||||
{
|
||||
$photo = stream_get_contents($photo);
|
||||
}
|
||||
if (empty($photo) || !($image = imagecreatefromstring($photo)))
|
||||
{
|
||||
error_log(__METHOD__."() invalid image!");
|
||||
return null;
|
||||
}
|
||||
$src_w = imagesx($image);
|
||||
$src_h = imagesy($image);
|
||||
//error_log(__METHOD__."() got image $src_w * $src_h, is_jpeg=".array2string(substr($photo,0,2) === "\377\330"));
|
||||
|
||||
// if $photo is to width or not a jpeg image --> resize it
|
||||
if ($src_w > $dst_w || substr($photo,0,2) !== "\377\330")
|
||||
{
|
||||
// scale the image to a width of 60 and a height according to the proportion of the source image
|
||||
$resized = imagecreatetruecolor($dst_w,$dst_h = round($src_h * $dst_w / $src_w));
|
||||
imagecopyresized($resized,$image,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
|
||||
|
||||
ob_start();
|
||||
imagejpeg($resized,'',90);
|
||||
$photo = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
imagedestroy($resized);
|
||||
//error_log(__METHOD__."() resized image $src_w*$src_h to $dst_w*$dst_h");
|
||||
}
|
||||
imagedestroy($image);
|
||||
|
||||
return $photo;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads contacts matched by key and puts all cols in the data array
|
||||
*
|
||||
|
@ -1253,9 +1253,11 @@ class addressbook_ui extends addressbook_bo
|
||||
case 'apply':
|
||||
if ($content['delete_photo']) $content['jpegphoto'] = null;
|
||||
if (is_array($content['upload_photo']) && !empty($content['upload_photo']['tmp_name']) &&
|
||||
$content['upload_photo']['tmp_name'] != 'none')
|
||||
$content['upload_photo']['tmp_name'] != 'none' &&
|
||||
($f = fopen($content['upload_photo']['tmp_name'],'r')))
|
||||
{
|
||||
$content['jpegphoto'] = $this->resize_photo($content['upload_photo']);
|
||||
$content['jpegphoto'] = $this->resize_photo($f);
|
||||
fclose($f);
|
||||
unset($content['upload_photo']);
|
||||
}
|
||||
$links = false;
|
||||
@ -1613,50 +1615,6 @@ class addressbook_ui extends addressbook_bo
|
||||
return $response->getXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* resizes the uploaded photo to 60*80 pixel and returns it
|
||||
*
|
||||
* @param array $file info uploaded file
|
||||
* @return string with resized jpeg photo
|
||||
*/
|
||||
function resize_photo($file)
|
||||
{
|
||||
switch($file['type'])
|
||||
{
|
||||
case 'image/gif':
|
||||
$upload = imagecreatefromgif($file['tmp_name']);
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/pjpeg':
|
||||
$upload = imagecreatefromjpeg($file['tmp_name']);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
$upload = imagecreatefrompng($file['tmp_name']);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
if (!$upload) return null;
|
||||
|
||||
list($src_w,$src_h) = getimagesize($file['tmp_name']);
|
||||
|
||||
// scale the image to a width of 60 and a height according to the proportion of the source image
|
||||
$photo = imagecreatetruecolor($dst_w = 60,$dst_h = round($src_h * 60 / $src_w));
|
||||
imagecopyresized($photo,$upload,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
|
||||
//echo "<p>imagecopyresized(\$photo,\$upload,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);</p>\n";
|
||||
|
||||
ob_start();
|
||||
imagejpeg($photo,'',90);
|
||||
$jpeg = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
imagedestroy($photo);
|
||||
imagedestroy($upload);
|
||||
|
||||
return $jpeg;
|
||||
}
|
||||
|
||||
function view($content=null)
|
||||
{
|
||||
if(is_array($content))
|
||||
|
Loading…
Reference in New Issue
Block a user