예제 #1
0
 /**
  * @param FileInterface $file
  */
 protected function guardFileExists(FileInterface $file)
 {
     $location = $file->getPath();
     if (!$this->filesystem->exists($location)) {
         throw new \RuntimeException('File does not exist: ' . $location);
     }
 }
예제 #2
0
 /**
  * @param FileInterface $file
  *
  * @return array
  */
 protected function parseIdentify(FileInterface $file, array $options = [])
 {
     try {
         $image = $this->imagick;
         $image->readImage($file->getPath());
         $identifyData = $image->identifyImage();
         if (isset($options['extended']) && $options['extended']) {
             $identifyData['hasSpotColors'] = $this->hasSpotColors($image);
         }
         $image->clear();
     } catch (\Exception $e) {
         return [];
     }
     return $identifyData;
 }
예제 #3
0
 /**
  * @param FileInterface $file
  *
  * @return array
  */
 protected function parseIdentify(FileInterface $file, array $options = [])
 {
     try {
         $image = $this->imagick;
         $format = strtolower(pathinfo($file->getPath(), PATHINFO_EXTENSION));
         $source = $this->alterSource($file->getPath(), $format);
         $image->readImage($source);
         $this->handleMultiPages($image);
         $identifyData = $image->identifyImage();
         if (isset($options['extended']) && $options['extended']) {
             $identifyData['hasSpotColors'] = $this->hasSpotColors($image);
         }
         $image->clear();
     } catch (\Exception $e) {
         return [];
     }
     return $identifyData;
 }
예제 #4
0
 /**
  * @param FileInterface $file
  * @param string        $tag
  *
  * @return mixed
  */
 public function scanFile(FileInterface $file, $tag = null)
 {
     // Create process
     $processBuilder = $this->createProcessBuilder();
     // Add basic parameters:
     $processBuilder->setArguments(['-g', '-json', '-struct']);
     // Set tag if it is configured
     if ($tag) {
         $this->guardIsValidTag($tag);
         $processBuilder->add('-' . strtolower($tag) . ':all');
     }
     // Add the file
     $processBuilder->add($file->getPath());
     // Run process:
     $process = $processBuilder->getProcess();
     $result = $this->runProcess($process);
     return $result[0];
 }