コード例 #1
0
 /**
  * {@inheritDoc}
  */
 public function tmb(Response $response, array $targets)
 {
     $data = ['images' => [], 'tmb' => false];
     $manager = $this->getImageManager();
     if (!empty($this->driverOptions['tmbPath']) && !empty($this->driverOptions['path'])) {
         foreach ($targets as $target) {
             $pInfo = pathinfo($target);
             $tmbPath = $pInfo['dirname'] . DIRECTORY_SEPARATOR . $this->driverOptions['tmbPath'] . DIRECTORY_SEPARATOR;
             if (!file_exists($tmbPath)) {
                 mkdir($tmbPath);
             }
             $filename = FileInfo::createHash($target, $this->driverId);
             $tmbFile = $tmbPath . $pInfo['basename'];
             $image = $manager->make($target);
             $image->fit($this->driverOptions['tmbSize']);
             $image->save($tmbFile);
             $data['images'][$filename] = DIRECTORY_SEPARATOR . $tmbFile;
         }
     }
     return new JsonResponse($data);
 }