Esempio n. 1
0
 /**
  * Retrieves an image with the given filter applied.
  *
  * @param string $filter
  * @param string $path
  *
  * @throws \LogicException
  *
  * @return \Liip\ImagineBundle\Binary\BinaryInterface
  */
 public function find($filter, $path)
 {
     $loader = $this->getLoader($filter);
     $binary = $loader->find($path);
     if (!$binary instanceof BinaryInterface) {
         $mimeType = $this->mimeTypeGuesser->guess($binary);
         $binary = new Binary($binary, $mimeType, $this->extensionGuesser->guess($mimeType));
     }
     if (null === $binary->getMimeType()) {
         throw new \LogicException(sprintf('The mime type of image %s was not guessed.', $path));
     }
     if (0 !== strpos($binary->getMimeType(), 'image/')) {
         throw new \LogicException(sprintf('The mime type of image %s must be image/xxx got %s.', $path, $binary->getMimeType()));
     }
     return $binary;
 }
Esempio n. 2
0
 public function testAllowGetFormatSetInConstructor()
 {
     $image = new Binary('aContent', 'image/png', 'png');
     $this->assertEquals('png', $image->getFormat());
 }