/** * Return the box for a spec * * @param Specification\Image $spec * @param integer $width * @param integer $height * * @return \Image\Box */ protected function boxFromSize(Image $spec, $width, $height) { if (!$spec->getWidth() && !$spec->getHeight()) { throw new InvalidArgumentException('The specification you provide must have width nad height'); } if ($spec->getResizeMode() == Image::RESIZE_MODE_INBOUND_FIXEDRATIO) { $ratioOut = $spec->getWidth() / $spec->getHeight(); $ratioIn = $width / $height; if ($ratioOut > $ratioIn) { $outHeight = round($spec->getHeight()); $outWidth = round($ratioIn * $outHeight); } else { $outWidth = round($spec->getWidth()); $outHeight = round($outWidth / $ratioIn); } return new Box($outWidth, $outHeight); } return new Box($spec->getWidth(), $spec->getHeight()); }
/** * @covers MediaAlchemyst\Specification\Image::setResizeMode * @covers MediaAlchemyst\Specification\Image::getResizeMode */ public function testSetResizeMode() { $this->assertEquals(Image::RESIZE_MODE_INBOUND_FIXEDRATIO, $this->object->getResizeMode()); $this->object->setResizeMode(Image::RESIZE_MODE_OUTBOUND); $this->assertEquals(Image::RESIZE_MODE_OUTBOUND, $this->object->getResizeMode()); }