mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
Merge pull request #1030 from gvde/fix-thumbnail-cache
Parse data: photo data uris.
This commit is contained in:
commit
3fc77e00aa
@ -407,9 +407,28 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
public function getPhoto() {
|
public function getPhoto() {
|
||||||
$image = new \OCP\Image();
|
$image = new \OCP\Image();
|
||||||
|
|
||||||
if (isset($this->PHOTO) && $image->loadFromData($this->PHOTO->getValue())) {
|
if (isset($this->PHOTO)) {
|
||||||
return $image;
|
$photo = $this->PHOTO;
|
||||||
} elseif (isset($this->LOGO) && $image->loadFromData($this->LOGO->getValue())) {
|
} elseif (isset($this->LOGO)) {
|
||||||
|
$photo = $this->LOGO;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$photovalue = $photo->getValue();
|
||||||
|
|
||||||
|
if ( $photo instanceof \Sabre\VObject\Property\Uri && substr($photovalue, 0, 5) === 'data:' ) {
|
||||||
|
$mimeType = substr($photovalue, 5, strpos($photovalue, ',')-5);
|
||||||
|
if (strpos($mimeType, ';')) {
|
||||||
|
$mimeType = substr($mimeType,0,strpos($mimeType, ';'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$photovalue = substr($photovalue, strpos($photovalue,',')+1);
|
||||||
|
|
||||||
|
if ($image->loadFromBase64($photovalue)) {
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
} elseif ($image->loadFromData($photovalue)) {
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,8 +333,22 @@ Class Properties {
|
|||||||
$app = new App();
|
$app = new App();
|
||||||
$vCard = $app->getContact($backendName, $addressBookId, $contactId);
|
$vCard = $app->getContact($backendName, $addressBookId, $contactId);
|
||||||
}
|
}
|
||||||
|
if (!isset($vCard->PHOTO)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
$image = new \OCP\Image();
|
$image = new \OCP\Image();
|
||||||
if (!isset($vCard->PHOTO) || !$image->loadFromBase64((string)$vCard->PHOTO)) {
|
$photostring = (string) $vCard->PHOTO;
|
||||||
|
|
||||||
|
if ( $vCard->PHOTO instanceof \Sabre\VObject\Property\Uri && substr($photostring, 0, 5) === 'data:' ) {
|
||||||
|
$mimeType = substr($photostring, 5, strpos($photostring, ',')-5);
|
||||||
|
if (strpos($mimeType, ';')) {
|
||||||
|
$mimeType = substr($mimeType,0,strpos($mimeType, ';'));
|
||||||
|
}
|
||||||
|
$photostring = substr($photostring, strpos($photostring,',')+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$image->loadFromBase64($photostring)) {
|
||||||
|
#\OCP\Util::writeLog('contacts', __METHOD__.', photo: ' . print_r($photostring, true), \OCP\Util::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user