diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index d380c35a..8f2ffb12 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -413,6 +413,28 @@ class Image return $this->resize($width, $height, true); } + /** + * Resize image to new width, constraining proportions + * + * @param integer $width + * @return Image + */ + public function widen($width) + { + return $this->resize($width, null, true); + } + + /** + * Resize image to new height, constraining proportions + * + * @param integer $height + * @return Image + */ + public function heighten($height) + { + return $this->resize(null, $height, true); + } + /** * Resize image canvas * diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 450a036f..195f1329 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -285,6 +285,40 @@ class ImageTest extends PHPUnit_Framework_Testcase $this->assertEquals($img->height, $original_height); } + public function testWidenImage() + { + $img = $this->getTestImage(); + + $img->widen(100); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 100); + $this->assertEquals($img->height, 75); + + $img->widen(1000); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 1000); + $this->assertEquals($img->height, 750); + } + + public function testHeightenImage() + { + $img = $this->getTestImage(); + + $img->heighten(150); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 200); + $this->assertEquals($img->height, 150); + + $img->heighten(900); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 1200); + $this->assertEquals($img->height, 900); + } + public function testResizeCanvas() { $img = $this->getTestImage();