/**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getPhoto($maxSize = 170)
 {
     // TODO: Cache resized photo
     $params = $this->request->urlParams;
     $etag = null;
     $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
     $contact = $addressBook->getChild($params['contactId']);
     $tempPhoto = TemporaryPhoto::create($this->cache, TemporaryPhoto::PHOTO_CURRENT, $contact);
     if ($tempPhoto->isValid()) {
         $image = $tempPhoto->getPhoto();
         $response = new ImageResponse($image);
         $lastModified = $contact->lastModified();
         // Force refresh if modified within the last minute.
         if (!is_null($lastModified)) {
             $response->setLastModified(\DateTime::createFromFormat('U', $lastModified) ?: null);
         }
         if (!is_null($etag)) {
             $response->setETag($etag);
         }
         if ($image->width() > $maxSize || $image->height() > $maxSize) {
             $image->resize($maxSize);
         }
         return $response;
     } else {
         return array("data" => array("FN" => $contact->getDisplayName()));
     }
 }
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getPhoto($maxSize = 170)
 {
     // TODO: Cache resized photo
     $params = $this->request->urlParams;
     $etag = null;
     //$maxSize = isset($this->request['maxSize']) ? $this->request['maxSize'] : 170;
     $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
     $contact = $addressBook->getChild($params['contactId']);
     if (!$contact) {
         $response = new JSONResponse();
         $response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
         return $response;
     }
     $image = new \OCP\Image();
     if (isset($contact->PHOTO) && $image->loadFromBase64((string) $contact->PHOTO)) {
         // OK
         $etag = md5($contact->PHOTO);
     } else {
         // Logo :-/
         if (isset($contact->LOGO) && $image->loadFromBase64((string) $contact->LOGO)) {
             // OK
             $etag = md5($contact->LOGO);
         }
     }
     if ($image->valid()) {
         $response = new ImageResponse($image);
         $lastModified = $contact->lastModified();
         // Force refresh if modified within the last minute.
         if (!is_null($lastModified)) {
             $response->setLastModified(\DateTime::createFromFormat('U', $lastModified) ?: null);
         }
         if (!is_null($etag)) {
             $response->setETag($etag);
         }
         if ($image->width() > $maxSize || $image->height() > $maxSize) {
             $image->resize($maxSize);
         }
         return $response;
     } else {
         $response = new JSONResponse();
         $response->bailOut(App::$l10n->t('Error getting user photo'));
         return $response;
     }
 }