eZ\Bundle\EzPublishCoreBundle\Imagine\Filter\Loader\ScaleFilterLoader::load PHP Method

load() public method

public load ( Imagine\Image\ImageInterface $image, array $options = [] )
$image Imagine\Image\ImageInterface
$options array
    public function load(ImageInterface $image, array $options = array())
    {
        if (count($options) < 2) {
            throw new InvalidArgumentException('Missing width and/or height options');
        }
        list($width, $height) = $options;
        $size = $image->getSize();
        $ratioWidth = $width / $size->getWidth();
        $ratioHeight = $height / $size->getHeight();
        // We shall use the side which has the lowest ratio with target value
        // as $width and $height are always maximum values.
        if ($ratioWidth <= $ratioHeight) {
            $method = 'widen';
            $value = $width;
        } else {
            $method = 'heighten';
            $value = $height;
        }
        return $this->innerLoader->load($image, array($method => $value));
    }

Usage Example

 public function testLoadWiden()
 {
     $width = 900;
     $height = 600;
     $origWidth = 770;
     $origHeight = 377;
     $box = new Box($origWidth, $origHeight);
     $image = $this->getMock('\\Imagine\\Image\\ImageInterface');
     $image->expects($this->once())->method('getSize')->will($this->returnValue($box));
     $this->innerLoader->expects($this->once())->method('load')->with($image, $this->equalTo(array('widen' => $width)))->will($this->returnValue($image));
     $this->assertSame($image, $this->loader->load($image, array($width, $height)));
 }
ScaleFilterLoader