Esempio n. 1
0
 /**
  * @brief sets an image as ownCloud avatar
  * @return null
  */
 private function setOwnCloudAvatar()
 {
     if (!$this->image->valid()) {
         $this->log->log('user_ldap', 'jpegPhoto data invalid for ' . $this->dn, \OCP\Util::ERROR);
         return;
     }
     //make sure it is a square and not bigger than 128x128
     $size = min(array($this->image->width(), $this->image->height(), 128));
     if (!$this->image->centerCrop($size)) {
         $this->log->log('user_ldap', 'croping image for avatar failed for ' . $this->dn, \OCP\Util::ERROR);
         return;
     }
     if (!$this->fs->isLoaded()) {
         $this->fs->setup($this->uid);
     }
     $avatar = $this->avatarManager->getAvatar($this->uid);
     $avatar->set($this->image);
 }
Esempio n. 2
0
 /**
  * @brief sets an image as ownCloud avatar
  * @return null
  */
 private function setOwnCloudAvatar()
 {
     if (!$this->image->valid()) {
         $this->log->log('jpegPhoto data invalid for ' . $this->dn, \OCP\Util::ERROR);
         return;
     }
     //make sure it is a square and not bigger than 128x128
     $size = min(array($this->image->width(), $this->image->height(), 128));
     if (!$this->image->centerCrop($size)) {
         $this->log->log('croping image for avatar failed for ' . $this->dn, \OCP\Util::ERROR);
         return;
     }
     if (!$this->fs->isLoaded()) {
         $this->fs->setup($this->uid);
     }
     try {
         $avatar = $this->avatarManager->getAvatar($this->uid);
         $avatar->set($this->image);
     } catch (\Exception $e) {
         \OC::$server->getLogger()->notice('Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), ['app' => 'user_ldap']);
     }
 }
Esempio n. 3
0
 /**
  * Get and set facebook profile picture
  */
 public function setPhoto()
 {
     if (isset($this->vcard->FBID)) {
         $img = file_get_contents("https://graph.facebook.com/" . $this->getFBID() . "/picture?height=1000");
         $image = new Image(base64_encode($img));
         // Center auto crop!!
         $image->centerCrop();
         if ($image->height() < 100 || $image->width() < 100) {
             // Maybe the graph API is disabled ?
             // Let's try to get the pic anyway
             $imgAltUrl = $this->fbController->getPicture_alt($this->getFBID());
             if (!$imgAltUrl) {
                 return array("error" => "Image unreachable", "id" => $this->id, "name" => $this->getName(), "addressbook" => $this->addressbook, "img" => $imgAltUrl, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100));
             } else {
                 if ($imgAltUrl == "notfound") {
                     return array("error" => "Wrong FBID, User not found", "id" => $this->id, "name" => $this->getName(), "addressbook" => $this->addressbook, "img" => $imgAltUrl, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100));
                 } else {
                     $imgAlt = file_get_contents($imgAltUrl);
                     $image = new Image(base64_encode($imgAlt));
                     // Center auto crop!!
                     $image->centerCrop();
                     if ($image->height() < 100 || $image->width() < 100) {
                         return array("error" => "Image too small", "id" => $this->id, "name" => $this->getName(), "addressbook" => $this->addressbook, "img" => $imgAltUrl, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100));
                     }
                 }
             }
         }
         // Image too big
         if ($image->width() > App::MAXPICTURESIZE || $image->height() > App::MAXPICTURESIZE) {
             $image->resize(App::MAXPICTURESIZE);
             // Prettier resizing than with browser and saves bandwidth.
         }
         // Image big enough or get without the graph API
         if (isset($this->vcard->PHOTO)) {
             unset($this->vcard->PHOTO);
         }
         // Add and save!
         $this->vcard->add('PHOTO', $image->data(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType()));
         $this->save();
         return array("error" => false, "id" => $this->id, "name" => $this->getName(), "name" => $this->getName(), "addressbook" => $this->addressbook, "photo" => isset($this->vcard->PHOTO), "photourl" => $this->getPhoto(100), "alt_method" => isset($imgAltUrl) ? $imgAltUrl : false);
     }
 }