* scaling now addressbook images uploaded via CardDAV or SyncML to 60 pixel width like already done for web GUI

This commit is contained in:
Ralf Becker 2010-11-04 20:43:59 +00:00
parent 647ab3e449
commit f45cb1b996
2 changed files with 1931 additions and 46 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1220,9 +1220,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;
@ -1553,50 +1555,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))