/** * 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::setDimensions * @covers MediaAlchemyst\Specification\Image::getWidth * @covers MediaAlchemyst\Specification\Image::getHeight */ public function testSetDimensions() { $this->object->setDimensions(320, 240); $this->assertEquals(320, $this->object->getWidth()); $this->assertEquals(240, $this->object->getHeight()); }