eZ\Bundle\EzPublishCoreBundle\Imagine\Filter\Loader\ScalePercentFilterLoader::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 percent options');
        }
        $size = $image->getSize();
        $origWidth = $size->getWidth();
        $origHeight = $size->getHeight();
        list($widthPercent, $heightPercent) = $options;
        $targetWidth = $origWidth * $widthPercent / 100;
        $targetHeight = $origHeight * $heightPercent / 100;
        return $this->innerLoader->load($image, array('size' => array($targetWidth, $targetHeight)));
    }

Usage Example

 public function testLoad()
 {
     $widthPercent = 40;
     $heightPercent = 125;
     $origWidth = 770;
     $origHeight = 377;
     $expectedWidth = $origWidth * $widthPercent / 100;
     $expectedHeight = $origHeight * $heightPercent / 100;
     $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('size' => array($expectedWidth, $expectedHeight))))->will($this->returnValue($image));
     $this->assertSame($image, $this->loader->load($image, array($widthPercent, $heightPercent)));
 }
ScalePercentFilterLoader