Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function load(ImageInterface $image, array $options = array())
 {
     $mode = ImageInterface::THUMBNAIL_OUTBOUND;
     if (!empty($options['mode']) && 'inset' === $options['mode']) {
         $mode = ImageInterface::THUMBNAIL_INSET;
     }
     if (!empty($options['filter'])) {
         $filter = constant('Imagine\\Image\\ImageInterface::FILTER_' . strtoupper($options['filter']));
     }
     if (empty($filter)) {
         $filter = ImageInterface::FILTER_UNDEFINED;
     }
     list($width, $height) = $options['size'];
     $size = $image->getSize();
     $origWidth = $size->getWidth();
     $origHeight = $size->getHeight();
     if (null === $width || null === $height) {
         if (null === $height) {
             $height = (int) ($width / $origWidth * $origHeight);
         } elseif (null === $width) {
             $width = (int) ($height / $origHeight * $origWidth);
         }
     }
     if ($origWidth > $width || $origHeight > $height || !empty($options['allow_upscale']) && ($origWidth !== $width || $origHeight !== $height)) {
         $filter = new Thumbnail(new Box($width, $height), $mode, $filter);
         $image = $filter->apply($image);
     }
     return $image;
 }
 public function testShouldMakeAThumbnail()
 {
     $image = $this->getImage();
     $thumbnail = $this->getImage();
     $size = new Box(50, 50);
     $filter = new Thumbnail($size);
     $image->expects($this->once())->method('thumbnail')->with($size, ManipulatorInterface::THUMBNAIL_INSET)->will($this->returnValue($thumbnail));
     $this->assertSame($thumbnail, $filter->apply($image));
 }