/** * Resize an image while maintaining the aspect ratio. * * Note that the returned data will most likely not be `$width`x`$height`, * but as close as possible while keeping the original aspect ratio. * * @param Image $image The input image * @param integer $width The maximum width * @param integer $height The maximum height * * @return void */ public function resizeKeepAspect(Image $image, $width, $height) { $originalWidth = $image->getWidth(); $originalHeight = $image->getHeight(); if ($originalWidth >= $originalHeight) { // Image is larger horizontally $scale = $width / $originalWidth; $height = $originalHeight * $scale; } else { // Image is larger vertically $scale = $height / $originalHeight; $width = $originalWidth * $scale; } return $this->resize($image, $width, $height); }
public function testItCanGetDimensions() { $image = new GDImage(__DIR__ . "/fixtures/image.png"); $this->assertEquals(100, $image->getWidth()); $this->assertEquals(100, $image->getHeight()); }