Esempio n. 1
0
 /**
  * Process the source, apply thumbnailer if set
  * @param string $source source to process
  * @return string source to be used by the html of this image tag
  * @throws zibo\ZiboException when the source file could not be found
  */
 private function processSource($source)
 {
     $fileSource = new File($source);
     if (!$fileSource->isAbsolute() && !String::startsWith($fileSource->getPath(), Zibo::DIRECTORY_APPLICATION . File::DIRECTORY_SEPARATOR)) {
         $fileSource = Zibo::getInstance()->getFile($fileSource->getPath());
         if (!$fileSource) {
             throw new ZiboException('Could not find ' . $source);
         }
     }
     $fileDestination = $this->getCacheFile($fileSource);
     if (!$fileDestination->exists() || $fileSource->getModificationTime() > $fileDestination->getModificationTime()) {
         $image = new CoreImage($fileSource);
         if ($this->thumbnailer) {
             $thumbnail = $image->thumbnail($this->thumbnailer, $this->thumbnailWidth, $this->thumbnailHeight);
             if ($image === $thumbnail) {
                 $fileSource->copy($fileDestination);
             } else {
                 $thumbnail->write($fileDestination);
             }
         } else {
             $fileSource->copy($fileDestination);
         }
     }
     // remove application/ from the path
     return substr($fileDestination->getPath(), 12);
 }