Example #1
0
 /**
  * @param File $file
  * @param int $width
  * @param int $height
  * @return string
  */
 public function getThumbImage(File $file, $width = 200, $height = 200)
 {
     $sourceImage = $file->getSavePath();
     $resultImage = $file->getSavePath() . '-' . $width . '-' . $height . '.' . $file->getFileExtension();
     if (!$this->getCacheFilesystem()->has($resultImage)) {
         try {
             $_file = $this->getFilesystem()->read($sourceImage);
             $image = WideImage::load($_file);
             $image_data = $image->resize($width, $height, 'outside')->crop('center', 'center', $width, $height)->asString($file->getFileExtension());
             $this->getCacheFilesystem()->write($resultImage, $image_data);
         } catch (\Exception $e) {
             throw new Exception\RuntimeException('File cannot be saved.', 0, $e);
         }
     }
     $fsAdapter = $this->getCacheFilesystem()->getAdapter();
     return str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', $fsAdapter->getPathPrefix() . $resultImage));
 }