Ejemplo n.º 1
0
 /**
  * Returns file metadata.
  *
  * @return array
  */
 public function getMetadata()
 {
     if (null === $this->metadata) {
         $filePath = $this->getFilePath();
         $this->metadata = $this->resourceType->getBackend()->getWithMetadata($filePath, array('mimetype', 'timestamp'));
     }
     return $this->metadata;
 }
 /**
  * @param ResourceType $sourceFileResourceType
  * @param string       $sourceFileDir
  * @param string       $sourceFileName
  * @param int          $requestedWidth
  * @param int          $requestedHeight
  */
 public function __construct(ResourceType $sourceFileResourceType, $sourceFileDir, $sourceFileName, $requestedWidth, $requestedHeight)
 {
     $this->sourceFileResourceType = $sourceFileResourceType;
     $this->sourceFileDir = $sourceFileDir;
     $this->sourceFileName = $sourceFileName;
     $this->requestedWidth = $requestedWidth;
     $this->requestedHeight = $requestedHeight;
     $this->backend = $sourceFileResourceType->getBackend();
 }
Ejemplo n.º 3
0
 /**
  * Returns backend assigned for current resource type
  *
  * @return Backend
  */
 public function getBackend()
 {
     return $this->resourceType->getBackend();
 }
 /**
  * @param ResourceType $sourceFileResourceType
  * @param string       $sourceFilePath
  * @param string       $sourceFileName
  * @param int          $width
  * @param int          $height
  *
  * @return ResizedImage|null
  */
 public function getResizedImageBySize(ResourceType $sourceFileResourceType, $sourceFilePath, $sourceFileName, $width, $height)
 {
     $resizedImagesPath = Path::combine($sourceFileResourceType->getDirectory(), $sourceFilePath, ResizedImage::DIR, $sourceFileName);
     $backend = $sourceFileResourceType->getBackend();
     if (!$backend->hasDirectory($resizedImagesPath)) {
         return null;
     }
     $resizedImagesFiles = array_filter($backend->listContents($resizedImagesPath), function ($v) {
         return isset($v['type']) && $v['type'] === 'file';
     });
     $thresholdPixels = $this->config->get('images.threshold.pixels');
     $thresholdPercent = (double) $this->config->get('images.threshold.percent') / 100;
     foreach ($resizedImagesFiles as $resizedImage) {
         $resizedImageSize = ResizedImage::getSizeFromFilename($resizedImage['basename']);
         $resizedImageWidth = $resizedImageSize['width'];
         $resizedImageHeight = $resizedImageSize['height'];
         if ($resizedImageWidth >= $width && ($resizedImageWidth <= $width + $thresholdPixels || $resizedImageWidth <= $width + $width * $thresholdPercent) && $resizedImageHeight >= $height && ($resizedImageHeight <= $height + $thresholdPixels || $resizedImageHeight <= $height + $height * $thresholdPercent)) {
             $resizedImage = new ResizedImage($this, $sourceFileResourceType, $sourceFilePath, $sourceFileName, $resizedImageWidth, $resizedImageHeight);
             if ($resizedImage->exists()) {
                 $resizedImage->load();
                 return $resizedImage;
             }
         }
     }
     return null;
 }
 /**
  * Creates a path in format:
  * [backend name]://backend/relative/path
  *
  * @param ResourceType $resourceType resource type
  * @param string       $path         backend relative path
  * @return string formatted path
  */
 protected function createPath(ResourceType $resourceType, $path)
 {
     return $resourceType->getBackend()->getName() . '://' . $path;
 }