Example #1
0
 private function create($imagePath, $square)
 {
     $galleryDir = \OC_User::getHome($this->user) . '/gallery/' . $this->user . '/';
     $dir = dirname($imagePath);
     $fileInfo = $this->view->getFileInfo($imagePath);
     if (!$fileInfo) {
         return false;
     }
     if (!is_dir($galleryDir . $dir)) {
         mkdir($galleryDir . $dir, 0755, true);
     }
     $this->image = new \OCP\Image();
     // check if file is encrypted
     if ($fileInfo['encrypted'] === true) {
         $fileName = $this->view->toTmpFile($imagePath);
     } else {
         $fileName = $this->view->getLocalFile($imagePath);
     }
     $this->image->loadFromFile($fileName);
     if ($this->image->valid()) {
         $this->image->fixOrientation();
         if ($square) {
             $this->image->centerCrop(200);
         } else {
             $this->image->fitIn($this->image->width(), 200);
             if ($this->image->width() > 600) {
                 // max aspect ratio of 3
                 $this->image->crop(($this->image->width() - 600) / 2, 0, 600, 200);
             }
         }
         $this->image->save($this->path);
     }
 }
Example #2
0
 /**
  * @return string
  */
 public static function toTmpFile($path)
 {
     return self::$defaultInstance->toTmpFile($path);
 }