Exemple #1
0
 /**
  * @brief reads jpegPhoto and set is as avatar if available
  * @param $uid string ownCloud user name
  * @param $dn string the user's LDAP DN
  * @return void
  */
 private function updateAvatar($uid, $dn)
 {
     $hasLoggedIn = \OCP\Config::getUserValue($uid, 'user_ldap', 'firstLoginAccomplished', 0);
     $lastChecked = \OCP\Config::getUserValue($uid, 'user_ldap', 'lastJpegPhotoLookup', 0);
     if ($hasLoggedIn !== '1' || time() - intval($lastChecked) < 86400) {
         //update only once a day
         return;
     }
     $avatarImage = $this->getAvatarImage($uid, $dn);
     if ($avatarImage === false) {
         //not set, nothing left to do;
         return;
     }
     $image = new \OCP\Image();
     $image->loadFromBase64(base64_encode($avatarImage));
     if (!$image->valid()) {
         \OCP\Util::writeLog('user_ldap', 'jpegPhoto data invalid for ' . $dn, \OCP\Util::ERROR);
         return;
     }
     //make sure it is a square and not bigger than 128x128
     $size = min(array($image->width(), $image->height(), 128));
     if (!$image->centerCrop($size)) {
         \OCP\Util::writeLog('user_ldap', 'croping image for avatar failed for ' . $dn, \OCP\Util::ERROR);
         return;
     }
     if (!\OC\Files\Filesystem::$loaded) {
         \OC_Util::setupFS($uid);
     }
     $avatarManager = \OC::$server->getAvatarManager();
     $avatar = $avatarManager->getAvatar($uid);
     $avatar->set($image);
 }
 /**
  * Get a photo from the oC cache for cropping.
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getTempPhoto()
 {
     $params = $this->request->urlParams;
     $tmpkey = $params['key'];
     $image = new \OCP\Image();
     $image->loadFromData($this->server->getCache()->get($tmpkey));
     if ($image->valid()) {
         $response = new ImageResponse($image);
         return $response;
     } else {
         $response = new JSONResponse();
         return $response->bailOut('Error getting temporary photo');
     }
 }
 /**
  * Get a photo from the oC cache for cropping.
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getTempPhoto()
 {
     $params = $this->request->urlParams;
     $tmpkey = $params['key'];
     $maxSize = isset($this->request->get['maxSize']) ? $this->request->get['maxSize'] : 400;
     $image = new \OCP\Image();
     $image->loadFromData($this->server->getCache()->get($tmpkey));
     if ($image->valid()) {
         if ($image->height() > $maxSize || $image->width() > $maxSize) {
             $image->resize($maxSize);
         }
         $response = new ImageResponse($image);
         return $response;
     } else {
         $response = new JSONResponse();
         return $response->bailOut('Error getting temporary photo');
     }
 }
Exemple #4
0
 /**
  * Generate thumbnail of an Image with GD
  * @param string $viewPath Source view path
  * @param string $srcImagePath Source image path relative to the ownCloud fakeroot
  * @param string $dstImagePath Destination image path
  * @return boolean TRUE image generated successfully, FALSE otherwise
  */
 private function generateImageThumbnailGD($viewPath, $srcImagePath, $dstImagePath)
 {
     $view = new \OC\Files\View($viewPath);
     $imageLocalPath = $view->getLocalFile($srcImagePath);
     $image = new \OCP\Image();
     $image->loadFromFile($imageLocalPath);
     if (!$image->valid()) {
         return FALSE;
     }
     //Non legge il path
     $image->fixOrientation();
     $image->resize($this->width);
     $imageRsrc = $image->resource();
     $height = $image->height();
     $width = $image->width();
     $widthOffset = intval(($this->width - $width) / 2);
     $heightOffset = intval(($this->height - $height) / 2);
     $thumbGDImage = imagecreatetruecolor($this->width, $this->height);
     // Fill with background color
     $bgColor = imagecolorallocate($thumbGDImage, $this->bgColor['red'], $this->bgColor['green'], $this->bgColor['blue']);
     imagefilledrectangle($thumbGDImage, 0, 0, $this->width, $this->height, $bgColor);
     imagecopyresampled($thumbGDImage, $imageRsrc, $widthOffset, $heightOffset, 0, 0, $width, $height, $width, $height);
     imagepng($thumbGDImage, $dstImagePath, 7);
     imagedestroy($thumbGDImage);
     return TRUE;
 }