Beispiel #1
0
 /**
  * Get an FS copy or original of this file and return the path.
  * Returns false on failure. Callers must not alter the file.
  * Temporary files are cleared automatically.
  *
  * @return string|bool False on failure
  */
 public function getLocalRefPath()
 {
     $this->assertRepoDefined();
     if (!isset($this->fsFile)) {
         $this->fsFile = $this->repo->getLocalReference($this->getPath());
         if (!$this->fsFile) {
             $this->fsFile = false;
             // null => false; cache negative hits
         }
     }
     return $this->fsFile ? $this->fsFile->getPath() : false;
 }
Beispiel #2
0
 /**
  * Returns the most appropriate source image for the thumbnail, given a target thumbnail size
  * @param array $params
  * @return array Source path and width/height of the source
  */
 public function getThumbnailSource($params)
 {
     if ($this->repo && $this->getHandler()->supportsBucketing() && isset($params['physicalWidth']) && ($bucket = $this->getThumbnailBucket($params['physicalWidth']))) {
         if ($this->getWidth() != 0) {
             $bucketHeight = round($this->getHeight() * ($bucket / $this->getWidth()));
         } else {
             $bucketHeight = 0;
         }
         // Try to avoid reading from storage if the file was generated by this script
         if (isset($this->tmpBucketedThumbCache[$bucket])) {
             $tmpPath = $this->tmpBucketedThumbCache[$bucket];
             if (file_exists($tmpPath)) {
                 return array('path' => $tmpPath, 'width' => $bucket, 'height' => $bucketHeight);
             }
         }
         $bucketPath = $this->getBucketThumbPath($bucket);
         if ($this->repo->fileExists($bucketPath)) {
             $fsFile = $this->repo->getLocalReference($bucketPath);
             if ($fsFile) {
                 return array('path' => $fsFile->getPath(), 'width' => $bucket, 'height' => $bucketHeight);
             }
         }
     }
     // Thumbnailing a very large file could result in network saturation if
     // everyone does it at once.
     if ($this->getSize() >= 10000000.0) {
         // 10MB
         $that = $this;
         $work = new PoolCounterWorkViaCallback('GetLocalFileCopy', sha1($this->getName()), array('doWork' => function () use($that) {
             return $that->getLocalRefPath();
         }));
         $srcPath = $work->execute();
     } else {
         $srcPath = $this->getLocalRefPath();
     }
     // Original file
     return array('path' => $srcPath, 'width' => $this->getWidth(), 'height' => $this->getHeight());
 }
 /**
  * Returns the most appropriate source image for the thumbnail, given a target thumbnail size
  * @param array $params
  * @return array Source path and width/height of the source
  */
 public function getThumbnailSource($params)
 {
     if ($this->repo && $this->getHandler()->supportsBucketing() && isset($params['physicalWidth']) && ($bucket = $this->getThumbnailBucket($params['physicalWidth']))) {
         if ($this->getWidth() != 0) {
             $bucketHeight = round($this->getHeight() * ($bucket / $this->getWidth()));
         } else {
             $bucketHeight = 0;
         }
         // Try to avoid reading from storage if the file was generated by this script
         if (isset($this->tmpBucketedThumbCache[$bucket])) {
             $tmpPath = $this->tmpBucketedThumbCache[$bucket];
             if (file_exists($tmpPath)) {
                 return array('path' => $tmpPath, 'width' => $bucket, 'height' => $bucketHeight);
             }
         }
         $bucketPath = $this->getBucketThumbPath($bucket);
         if ($this->repo->fileExists($bucketPath)) {
             $fsFile = $this->repo->getLocalReference($bucketPath);
             if ($fsFile) {
                 return array('path' => $fsFile->getPath(), 'width' => $bucket, 'height' => $bucketHeight);
             }
         }
     }
     // Original file
     return array('path' => $this->getLocalRefPath(), 'width' => $this->getWidth(), 'height' => $this->getHeight());
 }