예제 #1
0
 /**
  * Crop image if is not exists in alias.
  *
  * @param MediaInterface   $media
  * @param AliasManipulator $aliasManipulator
  */
 private function cropImage(MediaInterface $media, AliasManipulator $aliasManipulator)
 {
     $aliasName = $aliasManipulator->getAliasName();
     $aliasArray = $aliasManipulator->getAliasArray();
     $mediaPath = $aliasName . '/' . $media->getReference();
     if ($this->filesystemManipulator->has($mediaPath)) {
         return true;
     }
     $mediaOriginalPath = $this->originalDir . '/' . $media->getReference();
     if (!$this->filesystemManipulator->has($mediaOriginalPath)) {
         throw new \Exception('The file \'' . $mediaOriginalPath . '\' is not found.');
     }
     if ($aliasArray['focus'] === true) {
         $magicFocus = new Focus($this, $media);
         $magicFocus->setTargetSize($aliasArray['width'], $aliasArray['height'])->setFocus($media->getFocusLeft(), $media->getFocusTop())->apply($aliasName);
         return true;
     }
     $resize = new Resize($this, $media);
     $resize->setTargetSize($aliasArray['width'], $aliasArray['height'])->apply($aliasName);
     return true;
 }
 /**
  * Set alias, and return AliasManipulator.
  *
  * @param array|string|null $alias
  *
  * @return AliasManipulator
  */
 public function setAlias($alias)
 {
     $aliasManipulator = new AliasManipulator($this->originalDir, $this->alias);
     $aliasManipulator->setAlias($alias);
     return $aliasManipulator;
 }