mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +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
@ -630,7 +630,7 @@ class addressbook_bo extends addressbook_so
|
||||
function db2data($data, $date_format='ts')
|
||||
{
|
||||
static $fb_url = false;
|
||||
|
||||
|
||||
// convert timestamps from server-time in the db to user-time
|
||||
foreach ($this->timestamps as $name)
|
||||
{
|
||||
@ -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
|
||||
*
|
||||
@ -1294,10 +1341,10 @@ class addressbook_bo extends addressbook_so
|
||||
}
|
||||
// return only contacts with email set
|
||||
$options['filter'][] = "contact_email LIKE '%@%'";
|
||||
|
||||
|
||||
// let link query know, to append email to list
|
||||
$options['type'] = 'email';
|
||||
|
||||
|
||||
return $this->link_query($pattern,$options);
|
||||
}
|
||||
/**
|
||||
@ -1311,7 +1358,7 @@ class addressbook_bo extends addressbook_so
|
||||
{
|
||||
return $this->check_perms($check,$id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns info about contacts for calender
|
||||
*
|
||||
|
@ -46,7 +46,7 @@ class addressbook_ui extends addressbook_bo
|
||||
|
||||
/**
|
||||
* Fields to copy, default if nothing specified in config
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static public $copy_fields = array(
|
||||
@ -989,7 +989,7 @@ class addressbook_ui extends addressbook_bo
|
||||
$wildcard = $query['advanced_search']['meth_select'];
|
||||
unset($query['advanced_search']['meth_select']);
|
||||
}
|
||||
//if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home');
|
||||
//if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home');
|
||||
|
||||
$rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'],$id_only,
|
||||
$order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']);
|
||||
@ -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;
|
||||
@ -1269,7 +1271,7 @@ class addressbook_ui extends addressbook_bo
|
||||
$old_org_entry = $this->read($content['id']);
|
||||
$old_fullname = ($old_org_entry['n_fn'] ? $old_org_entry['n_fn'] : parent::fullname($old_org_entry));
|
||||
}
|
||||
if ( $content['n_fn'] != $fullname || $fullname != $old_fullname)
|
||||
if ( $content['n_fn'] != $fullname || $fullname != $old_fullname)
|
||||
{
|
||||
unset($content['n_fn']);
|
||||
}
|
||||
@ -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