/** * {@inheritDoc} */ public function load(ImageInterface $image, array $options = array()) { if (!isset($options['min'])) { throw new \InvalidArgumentException('Missing min option.'); } list($width, $height) = $options['min']; $size = $image->getSize(); $origWidth = $size->getWidth(); $origHeight = $size->getHeight(); if ($origWidth < $width || $origHeight < $height) { $widthRatio = $width / $origWidth; $heightRatio = $height / $origHeight; $ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio; $filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio)); return $filter->apply($image); } return $image; }
/** * @covers Imagine\Filter\Basic\Resize::apply * * @dataProvider getDataSet * * @param BoxInterface $size */ public function testShouldResizeImageAndReturnResult(BoxInterface $size) { $image = $this->getImage(); $image->expects($this->once())->method('resize')->with($size)->will($this->returnValue($image)); $command = new Resize($size); $this->assertSame($image, $command->apply($image)); }
/** * {@inheritDoc} */ public function load(ImageInterface $image, array $options = array()) { list($width, $height) = $options['size']; $filter = new Resize(new Box($width, $height)); return $filter->apply($image); }
/** * @param ImagineImageInterface $image * * @return ImagineImagineInterface */ public function updateFile(ImagineImageInterface $image = null) { if ($image === null) { $image = $this->image; } $target = $this->getTargetSize($image->getSize()->getWidth(), $image->getSize()->getHeight(), $this->targetWidth, $this->targetHeight); $resize = new ImagineResize(new Box($target['width'], $target['height'])); $image = $resize->apply($image); return $image; }
/** * @param ImagineImageInterface $image * * @return ImagineImageInterface */ public function updateFile(ImagineImageInterface $image) { $this->originWidth = $image->getSize()->getWidth(); $this->originHeight = $image->getSize()->getHeight(); // Resize $this->resize(); $resize = new ImagineResize(new Box($this->resizeWidth, $this->resizeHeight)); $image = $resize->apply($image); // Crop $this->crop(); $crop = new ImagineCrop(new Point($this->targetLeft, $this->targetTop), new Box($this->targetWidth, $this->targetHeight)); $image = $crop->apply($image); return $image; }